usrpserv/config/config.go

29 lines
453 B
Go
Raw Normal View History

2024-05-24 23:07:40 +01:00
package config
import (
"encoding/json"
"os"
)
type Config struct {
LocalAddr UDP `json:"localAddr"`
RemoteAddr UDP `json:"remoteAddr"`
}
type UDP struct {
IP string `json:"ip"`
Port int `json:"port"`
}
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
}