1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-06-10 13:09:11 -04:00
Files
v2fly/app/subscription/containers/jsonfieldarray/jsonified/parser.go

37 lines
1.1 KiB
Go
Raw Normal View History

2023-11-21 23:03:20 +00:00
package jsonified
import (
"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
"github.com/v2fly/v2ray-core/v5/app/subscription/containers/jsonfieldarray"
"github.com/v2fly/v2ray-core/v5/common"
jsonConf "github.com/v2fly/v2ray-core/v5/infra/conf/json"
)
func newJsonifiedYamlParser() containers.SubscriptionContainerDocumentParser {
return &jsonifiedYAMLParser{}
}
type jsonifiedYAMLParser struct{}
func (j jsonifiedYAMLParser) ParseSubscriptionContainerDocument(rawConfig []byte) (*containers.Container, error) {
parser := jsonfieldarray.NewJSONFieldArrayParser()
jsonified, err := jsonConf.FromYAML(rawConfig)
if err != nil {
return nil, newError("failed to parse as yaml").Base(err)
}
container, err := parser.ParseSubscriptionContainerDocument(jsonified)
if err != nil {
return nil, newError("failed to parse as jsonfieldarray").Base(err)
}
container.Kind = "Yaml2Json+" + container.Kind
for _, value := range container.ServerSpecs {
value.KindHint = "Yaml2Json+" + value.KindHint
}
return container, nil
}
func init() {
common.Must(containers.RegisterParser("Yaml2Json", newJsonifiedYamlParser()))
}