|
|
@@ -4,9 +4,6 @@ import (
|
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"io"
|
|
|
- "io/ioutil"
|
|
|
-
|
|
|
- "github.com/ghodss/yaml"
|
|
|
|
|
|
"v2ray.com/core"
|
|
|
"v2ray.com/core/common/errors"
|
|
|
@@ -70,22 +67,6 @@ func DecodeJSONConfig(reader io.Reader) (*conf.Config, error) {
|
|
|
return jsonConfig, nil
|
|
|
}
|
|
|
|
|
|
-// DecodeYAMLConfig reads from reader and decode the config into *conf.Config
|
|
|
-// syntax error could NOT be detected.
|
|
|
-func DecodeYAMLConfig(reader io.Reader) (*conf.Config, error) {
|
|
|
- yamlConfig := &conf.Config{}
|
|
|
-
|
|
|
- // Since v2ray use json.RawMessage a lot, so we use a wrapper to convert yaml to json
|
|
|
- if tmpBuf, err := ioutil.ReadAll(reader); err != nil {
|
|
|
- return nil, newError("failed to read").Base(err)
|
|
|
- } else if err := yaml.Unmarshal(tmpBuf, yamlConfig); err != nil {
|
|
|
- return nil, newError("failed to parse config").Base(err)
|
|
|
- }
|
|
|
-
|
|
|
- return yamlConfig, nil
|
|
|
-}
|
|
|
-
|
|
|
-// LoadJSONConfig uses content in reader to return a core.Config
|
|
|
func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
|
|
|
jsonConfig, err := DecodeJSONConfig(reader)
|
|
|
if err != nil {
|
|
|
@@ -99,18 +80,3 @@ func LoadJSONConfig(reader io.Reader) (*core.Config, error) {
|
|
|
|
|
|
return pbConfig, nil
|
|
|
}
|
|
|
-
|
|
|
-// LoadYAMLConfig uses content in reader to return a core.Config
|
|
|
-func LoadYAMLConfig(reader io.Reader) (*core.Config, error) {
|
|
|
- yamlConfig, err := DecodeYAMLConfig(reader)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- pbConfig, err := yamlConfig.Build()
|
|
|
- if err != nil {
|
|
|
- return nil, newError("failed to parse yaml config").Base(err)
|
|
|
- }
|
|
|
-
|
|
|
- return pbConfig, nil
|
|
|
-}
|