github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/conf/api.go (about) 1 package conf 2 3 import ( 4 "strings" 5 6 "v2ray.com/core/app/commander" 7 loggerservice "v2ray.com/core/app/log/command" 8 handlerservice "v2ray.com/core/app/proxyman/command" 9 statsservice "v2ray.com/core/app/stats/command" 10 "v2ray.com/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 "handlerservice": 27 services = append(services, serial.ToTypedMessage(&handlerservice.Config{})) 28 case "loggerservice": 29 services = append(services, serial.ToTypedMessage(&loggerservice.Config{})) 30 case "statsservice": 31 services = append(services, serial.ToTypedMessage(&statsservice.Config{})) 32 } 33 } 34 35 return &commander.Config{ 36 Tag: c.Tag, 37 Service: services, 38 }, nil 39 }