refactor: follow the google go style guide

Document every package and exported identifier, return the log level
from NewLogger instead of keeping it in a package variable, and stop
tests from mutating the argon2 parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:18:02 +01:00
1 parent 048e114fd9
commit d20225982a
21 files changed
+147 -36

No files matched your search

+17
View File
@@ -1,3 +1,5 @@
// Package config reads component settings from UPTIME_* environment
// variables.
package config
import (
@@ -8,13 +10,17 @@ import (
"github.com/caarlos0/env/v11"
)
// Edition switches features that only make sense when we operate the
// service, such as billing.
type Edition string
// Editions.
const (
EditionCloud Edition = "cloud"
EditionSelfHosted Edition = "selfhosted"
)
// Common holds settings shared by all components.
type Common struct {
Edition Edition `env:"UPTIME_EDITION" envDefault:"selfhosted"`
LogLevel slog.Level `env:"UPTIME_LOG_LEVEL" envDefault:"info"`
@@ -33,16 +39,21 @@ type Sentinel struct {
Password string `env:"UPTIME_REDIS_SENTINEL_PASSWORD"`
}
// Enabled reports whether a sentinel master name is configured.
func (s Sentinel) Enabled() bool { return s.Master != "" }
// SignupMode controls who may create an account and organization.
type SignupMode string
// Signup modes. SignupFirstUser allows exactly one account, the operator of a
// fresh self-hosted installation.
const (
SignupOpen SignupMode = "open"
SignupFirstUser SignupMode = "first-user"
SignupClosed SignupMode = "closed"
)
// API configures cmd/api.
type API struct {
Common
Listen string `env:"UPTIME_API_LISTEN" envDefault:":8080"`
@@ -52,6 +63,7 @@ type API struct {
SessionAbsolute time.Duration `env:"UPTIME_SESSION_ABSOLUTE" envDefault:"720h"`
}
// Validate checks API-specific settings in addition to Common.Validate.
func (a API) Validate() error {
if err := a.Common.Validate(); err != nil {
return err
@@ -70,17 +82,21 @@ func (a API) Validate() error {
return nil
}
// Checker configures cmd/checker. Region names the location this instance
// checks from and must match the regions assigned to monitors.
type Checker struct {
Common
Region string `env:"UPTIME_CHECKER_REGION,required,notEmpty"`
HealthListen string `env:"UPTIME_CHECKER_HEALTH_LISTEN" envDefault:":8081"`
}
// StatusPage configures cmd/statuspage.
type StatusPage struct {
Common
Listen string `env:"UPTIME_STATUSPAGE_LISTEN" envDefault:":8082"`
}
// Load parses the environment into a T, applying envDefault tags.
func Load[T any]() (T, error) {
var cfg T
if err := env.Parse(&cfg); err != nil {
@@ -89,6 +105,7 @@ func Load[T any]() (T, error) {
return cfg, nil
}
// Validate reports missing or contradictory settings.
func (c Common) Validate() error {
switch c.Edition {
case EditionCloud, EditionSelfHosted: