Skip to content

Commit

Permalink
feat: add environment variable loading to config
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed Apr 3, 2024
1 parent 79829de commit 7e03245
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"errors"
"net"
"os"
)

type Config struct {
Expand All @@ -27,3 +28,18 @@ func (c *Config) IsValid() error {
}
return nil
}

func (c *Config) LoadEnv() {
if os.Getenv("RLPA_LISTEN_ADDRESS") != "" {
c.ListenAddress = os.Getenv("RLPA_LISTEN_ADDRESS")
}
if os.Getenv("RLPA_LPAC_VERSION") != "" {
c.LpacVersion = os.Getenv("RLPA_LPAC_VERSION")
}
if os.Getenv("RLPA_DATA_DIR") != "" {
c.DataDir = os.Getenv("RLPA_DATA_DIR")
}
if os.Getenv("RLPA_DONT_DOWNLOAD") != "" {
c.DontDownload = true
}
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func init() {

func main() {
slog.Info("eSTK.me rlpa server", "version", Version)
config.C.LoadEnv()
if err := config.C.IsValid(); err != nil {
slog.Error("invalid configuration", "error", err)
os.Exit(1)
Expand Down

0 comments on commit 7e03245

Please sign in to comment.