| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package config
- import (
- "encoding/json"
- "os"
- )
- type Config struct {
- DHCP DHCPConfig `json:"dhcp"`
- DNS DNSConfig `json:"dns"`
- Web WebConfig `json:"web"`
- Database DatabaseConfig `json:"database"`
- }
- type DHCPConfig struct {
- Enabled bool `json:"enabled"`
- Interface string `json:"interface"`
- Network string `json:"network"`
- Netmask string `json:"netmask"`
- Gateway string `json:"gateway"`
- DNSServers []string `json:"dns_servers"`
- NTPServers []string `json:"ntp_servers"`
- BroadcastAddress string `json:"broadcast_address"`
- LeaseTime int `json:"lease_time"` // seconds
- IPPoolStart string `json:"ip_pool_start"`
- IPPoolEnd string `json:"ip_pool_end"`
- DomainName string `json:"domain_name"`
- ExcludedIPs []string `json:"excluded_ips"`
- }
- type DNSConfig struct {
- Enabled bool `json:"enabled"`
- ListenAddr string `json:"listen_addr"`
- ListenPort int `json:"listen_port"`
- Upstream []string `json:"upstream"`
- CacheSize int `json:"cache_size"`
- CacheTTL int `json:"cache_ttl"`
- Recursion bool `json:"recursion"`
- AllowQuery []string `json:"allow_query"`
- DNSSECValidation bool `json:"dnssec_validation"`
- }
- type WebConfig struct {
- Host string `json:"host"`
- Port int `json:"port"`
- SessionKey string `json:"session_key"`
- EnableHTTPS bool `json:"enable_https"`
- CertFile string `json:"https_cert"`
- KeyFile string `json:"https_key"`
- }
- type DatabaseConfig struct {
- Path string `json:"path"`
- }
- func LoadConfig(path string) (*Config, error) {
- data, err := os.ReadFile(path)
- if err != nil {
- return nil, err
- }
- var cfg Config
- if err := json.Unmarshal(data, &cfg); err != nil {
- return nil, err
- }
- return &cfg, nil
- }
- func (c *Config) Save(path string) error {
- data, err := json.MarshalIndent(c, "", " ")
- if err != nil {
- return err
- }
- return os.WriteFile(path, data, 0644)
- }
|