initial server implementation

This commit is contained in:
2026-05-31 17:35:41 -05:00
parent 686f54af64
commit 16cb057670
106 changed files with 102494 additions and 4 deletions
+35
View File
@@ -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
}