package config import "fmt" type AppConfig struct { ListenIP string `json:"listen_ip" yaml:"listen_ip" toml:"listen_ip" validate:"required,ip"` ListenPort int `json:"listen_port" yaml:"listen_port" toml:"listen_port" validate:"required"` } func (c *AppConfig) GenerateIP() string { return fmt.Sprintf("%s:%d", c.ListenIP, c.ListenPort) } func NewAppConfig(port *int, ip *string) AppConfig { defaultPort := 8080 defaultIp := "127.0.0.1" if port == nil { port = &defaultPort } if ip == nil { ip = &defaultIp } return AppConfig{ ListenIP: *ip, ListenPort: *port, } }