grain/relay/utils/loadConfig.go

48 lines
943 B
Go
Raw Normal View History

package utils
import (
2024-07-20 02:08:27 +00:00
"os"
"gopkg.in/yaml.v2"
)
2024-07-25 03:04:26 +00:00
type RateLimitConfig struct {
EventLimit float64 `yaml:"event_limit"`
EventBurst int `yaml:"event_burst"`
WsLimit float64 `yaml:"ws_limit"`
WsBurst int `yaml:"ws_burst"`
KindLimits []KindLimitConfig `yaml:"kind_limits"`
}
type KindLimitConfig struct {
Kind int `yaml:"kind"`
Limit float64 `yaml:"limit"`
Burst int `yaml:"burst"`
}
type Config struct {
MongoDB struct {
URI string `yaml:"uri"`
Database string `yaml:"database"`
} `yaml:"mongodb"`
Server struct {
2024-07-23 20:40:39 +00:00
Port string `yaml:"port"`
} `yaml:"server"`
2024-07-25 03:04:26 +00:00
RateLimit RateLimitConfig `yaml:"rate_limit"`
}
func LoadConfig(filename string) (*Config, error) {
2024-07-20 02:08:27 +00:00
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}
return &config, nil
}