Add the runnable Gitea, PostgreSQL, and Hop control-plane foundation
Hop-State: A_06FN3QYA1N56NQYGZ81DWGR Hop-Proposal: R_06FN3QXJRYPPEQZQA6S69QG Hop-Task: T_06FN3MVGY3MT82ESQ89BND0 Hop-Attempt: AT_06FN3MVGY092BFA5MR9C7EG
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
HTTPAddr string
|
||||
DatabaseURL string
|
||||
AdminToken string
|
||||
GiteaWebhookSecret string
|
||||
GiteaBaseURL string
|
||||
GiteaAPIToken string
|
||||
}
|
||||
|
||||
func Load() (Config, error) {
|
||||
cfg := Config{
|
||||
HTTPAddr: value("HOP_HTTP_ADDR", ":8080"),
|
||||
DatabaseURL: os.Getenv("HOP_DATABASE_URL"),
|
||||
AdminToken: os.Getenv("HOP_ADMIN_TOKEN"),
|
||||
GiteaWebhookSecret: os.Getenv("HOP_GITEA_WEBHOOK_SECRET"),
|
||||
GiteaBaseURL: value("GITEA_BASE_URL", "http://localhost:3000"),
|
||||
GiteaAPIToken: os.Getenv("GITEA_API_TOKEN"),
|
||||
}
|
||||
|
||||
if cfg.DatabaseURL == "" {
|
||||
return Config{}, errors.New("HOP_DATABASE_URL is required")
|
||||
}
|
||||
if cfg.AdminToken == "" {
|
||||
return Config{}, errors.New("HOP_ADMIN_TOKEN is required")
|
||||
}
|
||||
if len(cfg.AdminToken) < 16 {
|
||||
return Config{}, errors.New("HOP_ADMIN_TOKEN must be at least 16 characters")
|
||||
}
|
||||
if cfg.GiteaWebhookSecret == "" {
|
||||
return Config{}, errors.New("HOP_GITEA_WEBHOOK_SECRET is required")
|
||||
}
|
||||
if len(cfg.GiteaWebhookSecret) < 16 {
|
||||
return Config{}, errors.New("HOP_GITEA_WEBHOOK_SECRET must be at least 16 characters")
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func value(name, fallback string) string {
|
||||
if v := os.Getenv(name); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user