github.com/eagleql/xray-core@v1.4.4/infra/conf/api.go (about) 1 package conf 2 3 import ( 4 "strings" 5 6 "github.com/eagleql/xray-core/app/commander" 7 loggerservice "github.com/eagleql/xray-core/app/log/command" 8 handlerservice "github.com/eagleql/xray-core/app/proxyman/command" 9 statsservice "github.com/eagleql/xray-core/app/stats/command" 10 "github.com/eagleql/xray-core/common/serial" 11 ) 12 13 type APIConfig struct { 14 Tag string `json:"tag"` 15 Services []string `json:"services"` 16 } 17 18 func (c *APIConfig) Build() (*commander.Config, error) { 19 if c.Tag == "" { 20 return nil, newError("API tag can't be empty.") 21 } 22 23 services := make([]*serial.TypedMessage, 0, 16) 24 for _, s := range c.Services { 25 switch strings.ToLower(s) { 26 case "reflectionservice": 27 services = append(services, serial.ToTypedMessage(&commander.ReflectionConfig{})) 28 case "handlerservice": 29 services = append(services, serial.ToTypedMessage(&handlerservice.Config{})) 30 case "loggerservice": 31 services = append(services, serial.ToTypedMessage(&loggerservice.Config{})) 32 case "statsservice": 33 services = append(services, serial.ToTypedMessage(&statsservice.Config{})) 34 } 35 } 36 37 return &commander.Config{ 38 Tag: c.Tag, 39 Service: services, 40 }, nil 41 }