Skip to content

Commit

Permalink
Update config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rxdn committed Nov 16, 2024
1 parent 5f3ba17 commit 737eecf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/cleanuser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (

func main() {
flag.Parse()
cfg := config.Parse()
cfg := config.Parse[config.CliConfig]()

// ensure only one is set
if *ticketIds == "" && !*all && *csv == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/deletetranscript/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (

func main() {
flag.Parse()
cfg := config.Parse()
cfg := config.Parse[config.CliConfig]()

if guildId == nil || *guildId == 0 {
panic("guild id must be set")
Expand Down
2 changes: 1 addition & 1 deletion cmd/exportguild/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (

func main() {
flag.Parse()
conf := config.Parse()
conf := config.Parse[config.CliConfig]()

// create minio client
m, err := minio.New(conf.Endpoint, &minio.Options{
Expand Down
2 changes: 1 addition & 1 deletion cmd/logarchiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func main() {
conf := config.Parse()
conf := config.Parse[config.Config]()

if err := sentry.Init(sentry.ClientOptions{
Dsn: conf.SentryDsn,
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/cliconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

type CliConfig struct {
AccessKey string `env:"S3_ACCESS,required"`
SecretKey string `env:"S3_SECRET,required"`
Endpoint string `env:"S3_ENDPOINT,required"`
Bucket string `env:"S3_BUCKET,required"`
}
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct {
DatabaseUri string `env:"DATABASE_URI"`
}

func Parse() (conf Config) {
func Parse[T any]() (conf T) {
parsers := env.CustomParsers{
reflect.TypeOf(uuid.UUID{}): func(value string) (interface{}, error) {
return uuid.Parse(value)
Expand Down

0 comments on commit 737eecf

Please sign in to comment.