All checks were successful
check / check (push) Successful in 2m24s
Complete rename of the application from `chat` to `neoirc` with binary name `neoircd`. closes #46 ## Changes - **Go module path**: `git.eeqj.de/sneak/chat` → `git.eeqj.de/sneak/neoirc` - **Server binary**: `chatd` → `neoircd` - **CLI binary**: `chat-cli` → `neoirc-cli` - **Cmd directories**: `cmd/chatd` → `cmd/neoircd`, `cmd/chat-cli` → `cmd/neoirc-cli` - **Go package**: `chatapi` → `neoircapi` - **Makefile**: binary name, build targets, docker image tag, clean target - **Dockerfile**: binary paths, user/group names (`chat` → `neoirc`), ENTRYPOINT - **`.gitignore`/`.dockerignore`**: artifact names - **All Go imports and doc comments** - **Default server name**: `chat` → `neoirc` - **Web client**: localStorage keys (`chat_token`/`chat_channels` → `neoirc_token`/`neoirc_channels`), page title, default server display name - **Schema files**: all `$id` URLs and example hostnames - **README.md**: project name, all binary references, examples, directory tree - **AGENTS.md**: build command reference - **Test fixtures**: app name and channel names Docker build passes. All tests pass. <!-- session: agent:sdlc-manager:subagent:a4b8dbd3-a7c8-4fad-8239-bb5a64a9b3d6 --> Co-authored-by: clawbot <clawbot@noreply.eeqj.de> Reviewed-on: #47 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
// Package healthcheck provides health status reporting for the server.
|
|
package healthcheck
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"git.eeqj.de/sneak/neoirc/internal/config"
|
|
"git.eeqj.de/sneak/neoirc/internal/db"
|
|
"git.eeqj.de/sneak/neoirc/internal/globals"
|
|
"git.eeqj.de/sneak/neoirc/internal/logger"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// Params defines the dependencies for creating a Healthcheck.
|
|
type Params struct {
|
|
fx.In
|
|
|
|
Globals *globals.Globals
|
|
Config *config.Config
|
|
Logger *logger.Logger
|
|
Database *db.Database
|
|
}
|
|
|
|
// Healthcheck tracks server uptime and provides health status.
|
|
type Healthcheck struct {
|
|
// StartupTime records when the server started.
|
|
StartupTime time.Time
|
|
|
|
log *slog.Logger
|
|
params *Params
|
|
}
|
|
|
|
// New creates a new Healthcheck instance.
|
|
func New(
|
|
lifecycle fx.Lifecycle, params Params,
|
|
) (*Healthcheck, error) {
|
|
hcheck := &Healthcheck{ //nolint:exhaustruct // StartupTime set in OnStart
|
|
params: ¶ms,
|
|
log: params.Logger.Get(),
|
|
}
|
|
|
|
lifecycle.Append(fx.Hook{
|
|
OnStart: func(_ context.Context) error {
|
|
hcheck.StartupTime = time.Now()
|
|
|
|
return nil
|
|
},
|
|
OnStop: func(_ context.Context) error {
|
|
return nil
|
|
},
|
|
})
|
|
|
|
return hcheck, nil
|
|
}
|
|
|
|
// Response is the JSON response returned by the health endpoint.
|
|
type Response struct {
|
|
Status string `json:"status"`
|
|
Now string `json:"now"`
|
|
UptimeSeconds int64 `json:"uptimeSeconds"`
|
|
UptimeHuman string `json:"uptimeHuman"`
|
|
Version string `json:"version"`
|
|
Appname string `json:"appname"`
|
|
Maintenance bool `json:"maintenanceMode"`
|
|
}
|
|
|
|
// Healthcheck returns the current health status of the server.
|
|
func (hcheck *Healthcheck) Healthcheck() *Response {
|
|
return &Response{
|
|
Status: "ok",
|
|
Now: time.Now().UTC().Format(time.RFC3339Nano),
|
|
UptimeSeconds: int64(hcheck.uptime().Seconds()),
|
|
UptimeHuman: hcheck.uptime().String(),
|
|
Appname: hcheck.params.Globals.Appname,
|
|
Version: hcheck.params.Globals.Version,
|
|
Maintenance: hcheck.params.Config.MaintenanceMode,
|
|
}
|
|
}
|
|
|
|
func (hcheck *Healthcheck) uptime() time.Duration {
|
|
return time.Since(hcheck.StartupTime)
|
|
}
|