Skip to content

Commit

Permalink
fixup! config: remove viper and move to pure YAML files
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <me@sumnerevans.com>
  • Loading branch information
sumnerevans committed May 25, 2024
1 parent 4247bc5 commit 36b6047
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
17 changes: 5 additions & 12 deletions cmd/mineshspc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/rs/zerolog"
globallog "github.com/rs/zerolog/log"
"go.mau.fi/util/dbutil"
"go.mau.fi/util/exerrors"
"go.mau.fi/util/exzerolog"
"gopkg.in/yaml.v3"

Expand All @@ -32,21 +33,13 @@ func main() {
// Parse the configuration
var config config.Configuration
for _, filename := range configFilenames {
f, err := os.Open(filename)
if err != nil {
panic(err)
}
err = yaml.NewDecoder(f).Decode(&config)
if err != nil {
panic(err)
}
f := exerrors.Must(os.Open(filename))
exerrors.PanicIfNotNil(yaml.NewDecoder(f).Decode(&config))
exerrors.PanicIfNotNil(f.Close())
}

// Setup logging
log, err := config.Logging.Compile()
if err != nil {
panic(err)
}
log := exerrors.Must(config.Logging.Compile())
defaultCtxLog := log.With().Bool("default_context_log", true).Caller().Logger()
zerolog.TimeFieldFormat = time.RFC3339Nano
zerolog.CallerMarshalFunc = exzerolog.CallerWithFunctionName
Expand Down
11 changes: 3 additions & 8 deletions internal/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"go.mau.fi/util/dbutil"
"go.mau.fi/util/exerrors"
"go.mau.fi/zeroconfig"
)

Expand Down Expand Up @@ -51,14 +52,8 @@ func (c *Configuration) ReadSecretKey() []byte {
return []byte(c.JWTSecretKey)
}

if len(c.secretKeyBytes) > 0 {
return c.secretKeyBytes
}

var err error
c.secretKeyBytes, err = os.ReadFile(c.JWTSecretKeyFile)
if err != nil {
panic(err)
if len(c.secretKeyBytes) == 0 {
c.secretKeyBytes = exerrors.Must(os.ReadFile(c.JWTSecretKeyFile))
}
return c.secretKeyBytes
}

0 comments on commit 36b6047

Please sign in to comment.