initial server implementation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DBDriver string `mapstructure:"db_driver"`
|
||||
DBConnString string `mapstructure:"db_conn_string"`
|
||||
JWTSecret string `mapstructure:"jwt_secret"`
|
||||
SessionSecret string `mapstructure:"session_secret"`
|
||||
ServerPort int `mapstructure:"server_port"`
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
v := viper.New()
|
||||
v.SetConfigFile(path)
|
||||
|
||||
v.SetDefault("db_driver", "sqlite")
|
||||
v.SetDefault("db_conn_string", "file::memory:?cache=shared")
|
||||
v.SetDefault("server_port", 8080)
|
||||
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
return nil, fmt.Errorf("read config: %w", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := v.Unmarshal(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal config: %w", err)
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user