2024-07-20 01:09:42 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2024-07-20 02:08:27 +00:00
|
|
|
"os"
|
2024-07-20 01:09:42 +00:00
|
|
|
|
|
|
|
"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"`
|
|
|
|
}
|
|
|
|
|
2024-07-20 01:09:42 +00:00
|
|
|
type Config struct {
|
|
|
|
MongoDB struct {
|
|
|
|
URI string `yaml:"uri"`
|
|
|
|
Database string `yaml:"database"`
|
|
|
|
} `yaml:"mongodb"`
|
2024-07-25 02:09:54 +00:00
|
|
|
Server struct {
|
2024-07-23 20:40:39 +00:00
|
|
|
Port string `yaml:"port"`
|
2024-07-25 02:09:54 +00:00
|
|
|
} `yaml:"server"`
|
2024-07-25 03:04:26 +00:00
|
|
|
RateLimit RateLimitConfig `yaml:"rate_limit"`
|
2024-07-20 01:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig(filename string) (*Config, error) {
|
2024-07-20 02:08:27 +00:00
|
|
|
data, err := os.ReadFile(filename)
|
2024-07-20 01:09:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var config Config
|
|
|
|
err = yaml.Unmarshal(data, &config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &config, nil
|
|
|
|
}
|