usrpserv/config/config.go
2024-05-25 12:05:15 +01:00

37 lines
632 B
Go

package config
import (
"encoding/json"
"os"
)
type Config struct {
LocalAddr UDP `json:"localAddr"`
RemoteAddr UDP `json:"remoteAddr"`
Server Server `json:"server"`
}
type UDP struct {
IP string `json:"ip"`
Port int `json:"port"`
}
type Server struct {
Enable bool `json:"enable"`
Expire int64 `json:"expire"`
MAX int `json:"max"`
UDP UDP `json:"udp"`
}
func ParseConfig(file string) (*Config, error) {
raw, err := os.ReadFile(file)
if err != nil {
return nil, err
}
var config Config
if err = json.Unmarshal(raw, &config); err != nil {
return nil, err
}
return &config, nil
}