init, eod commit
This commit is contained in:
27
util/config/structs.go
Normal file
27
util/config/structs.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
import "log/slog"
|
||||
|
||||
type Config struct {
|
||||
Log LogConfig `toml:"log"`
|
||||
Gateway GatewayConfig `toml:"gateway"`
|
||||
Database DatabaseConfig `toml:"database"`
|
||||
}
|
||||
|
||||
type GatewayConfig struct {
|
||||
HttpPort string `toml:"http_port"`
|
||||
Websocket string `toml:"websocket"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Level slog.Level `toml:"level"`
|
||||
Directory string `toml:"directory"`
|
||||
Rotation int `toml:"rotation"`
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
HostDSN string `toml:"host_dsn"`
|
||||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
Database string `toml:"database"`
|
||||
}
|
||||
21
util/config/toml.go
Normal file
21
util/config/toml.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open config: %w", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err = toml.NewDecoder(file).Decode(&cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user