diff --git a/cmd/cleanuser/main.go b/cmd/cleanuser/main.go index 19d42cf..0aa0ea2 100644 --- a/cmd/cleanuser/main.go +++ b/cmd/cleanuser/main.go @@ -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 == "" { diff --git a/cmd/deletetranscript/main.go b/cmd/deletetranscript/main.go index d46c9dc..128dd9e 100644 --- a/cmd/deletetranscript/main.go +++ b/cmd/deletetranscript/main.go @@ -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") diff --git a/cmd/exportguild/main.go b/cmd/exportguild/main.go index 5f95e87..ce6798f 100644 --- a/cmd/exportguild/main.go +++ b/cmd/exportguild/main.go @@ -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{ diff --git a/cmd/logarchiver/main.go b/cmd/logarchiver/main.go index ef5a5dd..9552462 100644 --- a/cmd/logarchiver/main.go +++ b/cmd/logarchiver/main.go @@ -14,7 +14,7 @@ import ( ) func main() { - conf := config.Parse() + conf := config.Parse[config.Config]() if err := sentry.Init(sentry.ClientOptions{ Dsn: conf.SentryDsn, diff --git a/pkg/config/cliconfig.go b/pkg/config/cliconfig.go new file mode 100644 index 0000000..75a0007 --- /dev/null +++ b/pkg/config/cliconfig.go @@ -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"` +} diff --git a/pkg/config/config.go b/pkg/config/config.go index cd2bd5f..7ea1c56 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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)