start: add config system

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2025-12-13 00:14:18 +01:00
commit 115456258c
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
3 changed files with 57 additions and 10 deletions

30
internal/config/struct.go Normal file
View file

@ -0,0 +1,30 @@
package config
import (
"github.com/spf13/viper"
)
type Config struct {
Database struct {
Path string `mapstructure:"path"`
} `mapstructure:"database"`
}
func LoadConfig(path string) (*Config, error) {
v := viper.New()
v.SetConfigFile(path)
v.SetConfigType("yaml")
v.SetDefault("database.path", "./data/")
if err := v.ReadInConfig(); err != nil {
return nil, err
}
var cfg Config
if err := v.Unmarshal(&cfg); err != nil {
return nil, err
}
return &cfg, nil
}