This commit is contained in:
RPRX 2020-11-25 19:01:53 +08:00
parent 47d23e9972
commit c7f7c08ead
711 changed files with 82154 additions and 2 deletions

41
infra/conf/api.go Normal file
View file

@ -0,0 +1,41 @@
package conf
import (
"strings"
"github.com/xtls/xray-core/v1/app/commander"
loggerservice "github.com/xtls/xray-core/v1/app/log/command"
handlerservice "github.com/xtls/xray-core/v1/app/proxyman/command"
statsservice "github.com/xtls/xray-core/v1/app/stats/command"
"github.com/xtls/xray-core/v1/common/serial"
)
type APIConfig struct {
Tag string `json:"tag"`
Services []string `json:"services"`
}
func (c *APIConfig) Build() (*commander.Config, error) {
if c.Tag == "" {
return nil, newError("API tag can't be empty.")
}
services := make([]*serial.TypedMessage, 0, 16)
for _, s := range c.Services {
switch strings.ToLower(s) {
case "reflectionservice":
services = append(services, serial.ToTypedMessage(&commander.ReflectionConfig{}))
case "handlerservice":
services = append(services, serial.ToTypedMessage(&handlerservice.Config{}))
case "loggerservice":
services = append(services, serial.ToTypedMessage(&loggerservice.Config{}))
case "statsservice":
services = append(services, serial.ToTypedMessage(&statsservice.Config{}))
}
}
return &commander.Config{
Tag: c.Tag,
Service: services,
}, nil
}