github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/app/subscription/containers/jsonfieldarray/jsonified/parser.go (about) 1 package jsonified 2 3 import ( 4 "github.com/v2fly/v2ray-core/v5/app/subscription/containers" 5 "github.com/v2fly/v2ray-core/v5/app/subscription/containers/jsonfieldarray" 6 "github.com/v2fly/v2ray-core/v5/common" 7 jsonConf "github.com/v2fly/v2ray-core/v5/infra/conf/json" 8 ) 9 10 func newJsonifiedYamlParser() containers.SubscriptionContainerDocumentParser { 11 return &jsonifiedYAMLParser{} 12 } 13 14 type jsonifiedYAMLParser struct{} 15 16 func (j jsonifiedYAMLParser) ParseSubscriptionContainerDocument(rawConfig []byte) (*containers.Container, error) { 17 parser := jsonfieldarray.NewJSONFieldArrayParser() 18 jsonified, err := jsonConf.FromYAML(rawConfig) 19 if err != nil { 20 return nil, newError("failed to parse as yaml").Base(err) 21 } 22 container, err := parser.ParseSubscriptionContainerDocument(jsonified) 23 if err != nil { 24 return nil, newError("failed to parse as jsonfieldarray").Base(err) 25 } 26 container.Kind = "Yaml2Json+" + container.Kind 27 28 for _, value := range container.ServerSpecs { 29 value.KindHint = "Yaml2Json+" + value.KindHint 30 } 31 return container, nil 32 } 33 34 func init() { 35 common.Must(containers.RegisterParser("Yaml2Json", newJsonifiedYamlParser())) 36 }