initial POC

This commit is contained in:
2024-06-04 22:46:09 +02:00
commit d3a672694f
12 changed files with 781 additions and 0 deletions

35
internal/config/config.go Normal file
View File

@@ -0,0 +1,35 @@
package config
import (
"git.asperti.com/paspo/mail-autoconfig/internal/myerrors"
"github.com/gookit/validate"
"github.com/spf13/viper"
)
type Config struct {
HttpPort int `mapstructure:"PORT" validate:"required|int|min:1|max:65535"`
DBPath string `mapstructure:"DB_PATH" validate:"required"`
}
var AppConfig Config
func InitConfig() error {
var err error
viper.SetConfigType("env")
viper.AllowEmptyEnv(true)
viper.AutomaticEnv()
viper.SetDefault("PORT", 9000)
viper.SetDefault("DB_PATH", "./database.sqlite")
err = viper.Unmarshal(&AppConfig)
if err != nil {
return myerrors.ErrConfigParse
}
validation := validate.Struct(AppConfig)
if !validation.Validate() {
return myerrors.ErrConfigValidation
}
return nil
}