usrpserv/config/config.go

37 lines
632 B
Go
Raw Normal View History

2024-05-24 23:07:40 +01:00
package config
import (
"encoding/json"
"os"
)
type Config struct {
2024-05-25 12:05:15 +01:00
LocalAddr UDP `json:"localAddr"`
RemoteAddr UDP `json:"remoteAddr"`
Server Server `json:"server"`
2024-05-24 23:07:40 +01:00
}
type UDP struct {
IP string `json:"ip"`
Port int `json:"port"`
}
2024-05-25 12:05:15 +01:00
type Server struct {
Enable bool `json:"enable"`
Expire int64 `json:"expire"`
MAX int `json:"max"`
UDP UDP `json:"udp"`
}
2024-05-24 23:07:40 +01:00
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
}