dataRT/config/server.go

73 lines
1.2 KiB
Go
Raw Normal View History

2025-09-05 18:35:46 +08:00
package config
import "maps"
type serverConfig struct {
2025-09-19 16:17:46 +08:00
Name string `json:"name" yaml:"name"`
2025-09-05 18:35:46 +08:00
Port int `json:"port" yaml:"port"`
SSUType map[string]uint8 `json:"ssutype" yaml:"ssutype"`
}
func NewServerConfig() *serverConfig {
return new(serverConfig)
}
2025-09-19 16:17:46 +08:00
func (conf *serverConfig) GetName() string {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("server config is nil")
}
2025-09-19 16:17:46 +08:00
return conf.Name
2025-09-05 18:35:46 +08:00
}
2025-09-19 16:17:46 +08:00
func (conf *serverConfig) SetName(name string) *serverConfig {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("server config is nil")
}
2025-09-19 16:17:46 +08:00
conf.Name = name
return conf
2025-09-05 18:35:46 +08:00
}
func (conf *serverConfig) GetPort() int {
if conf == nil {
panic("server config is nil")
}
2025-09-19 16:17:46 +08:00
2025-09-05 18:35:46 +08:00
return conf.Port
}
2025-09-19 16:17:46 +08:00
func (conf *serverConfig) SetPort(port int) *serverConfig {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("server config is nil")
}
conf.Port = port
2025-09-19 16:17:46 +08:00
return conf
2025-09-05 18:35:46 +08:00
}
func (conf *serverConfig) GetSSUType() map[string]uint8 {
if conf == nil {
panic("server config is nil")
}
2025-09-19 16:17:46 +08:00
2025-09-05 18:35:46 +08:00
return conf.SSUType
}
2025-09-19 16:17:46 +08:00
func (conf *serverConfig) SetSSUType(ssuType map[string]uint8) *serverConfig {
2025-09-05 18:35:46 +08:00
if conf == nil {
panic("server config is nil")
}
if conf.SSUType == nil {
conf.SSUType = ssuType
} else {
maps.Copy(conf.SSUType, ssuType)
}
2025-09-19 16:17:46 +08:00
return conf
2025-09-05 18:35:46 +08:00
}
func serverConfigName() string {
return "server.json"
}