diff options
author | Alan Pearce | 2024-05-09 20:17:19 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-09 20:17:19 +0200 |
commit | 5573c4b7f7495f6e6cbb899cce8f8fa90425b01c (patch) | |
tree | 8a65b5aad4c7a62669ce1a10ad07b43476218f50 | |
parent | 9389b7dd633f6cc4653e6709a972cc7d6ab9e48f (diff) | |
download | searchix-5573c4b7f7495f6e6cbb899cce8f8fa90425b01c.tar.lz searchix-5573c4b7f7495f6e6cbb899cce8f8fa90425b01c.tar.zst searchix-5573c4b7f7495f6e6cbb899cce8f8fa90425b01c.zip |
refactor: clean up flags and environment variables
-rw-r--r-- | internal/server/server.go | 21 | ||||
-rw-r--r-- | serve/main.go | 10 |
2 files changed, 5 insertions, 26 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index e343434..f050e29 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -31,22 +31,16 @@ import ( var config *cfg.Config -var ( - CommitSHA string - ShortSHA string -) - type Config struct { - Production bool `conf:"default:false"` - InDevServer bool `conf:"default:false"` + Environment string `conf:"default:development"` LiveReload bool `conf:"default:false,flag:live"` - Root string `conf:"default:website"` ListenAddress string `conf:"default:localhost"` Port string `conf:"default:3000,short:p"` BaseURL cfg.URL `conf:"default:http://localhost:3000,short:b"` ConfigFile string `conf:"short:c"` LogLevel slog.Level `conf:"default:INFO"` IndexPath string `conf:"default:data/index.bleve"` + SentryDSN string } type HTTPError struct { @@ -98,16 +92,11 @@ func New(runtimeConfig *Config) (*Server, error) { log.Fatalf("could not open search index, error: %#v", err) } - env := "development" - if runtimeConfig.Production { - env = "production" - } err = sentry.Init(sentry.ClientOptions{ EnableTracing: true, TracesSampleRate: 1.0, - Dsn: os.Getenv("SENTRY_DSN"), - Release: CommitSHA, - Environment: env, + Dsn: runtimeConfig.SentryDSN, + Environment: runtimeConfig.Environment, }) if err != nil { return nil, errors.WithMessage(err, "could not set up sentry") @@ -284,7 +273,7 @@ func New(runtimeConfig *Config) (*Server, error) { } var logWriter io.Writer - if runtimeConfig.Production { + if runtimeConfig.Environment == "production" { logWriter = law.NewWriteAsyncer(os.Stdout, nil) } else { logWriter = os.Stdout diff --git a/serve/main.go b/serve/main.go index 5c68cc5..9ba2113 100644 --- a/serve/main.go +++ b/serve/main.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "log/slog" - "net/url" "os" "os/signal" "sync" @@ -15,11 +14,6 @@ import ( "github.com/pkg/errors" ) -var ( - CommitSHA string - ShortSHA string -) - func main() { runtimeConfig := server.Config{} help, err := conf.Parse("", &runtimeConfig) @@ -56,10 +50,6 @@ func main() { defer wg.Done() sErr <- sv.Start() }() - if !runtimeConfig.InDevServer { - url, _ := url.Parse("http://" + sv.Addr) - log.Printf("server listening on %s", url.String()) - } err = <-sErr if err != nil { |