1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-17 19:19:11 -04:00

rearrange loader

This commit is contained in:
vcptr
2019-12-16 09:33:41 +08:00
parent 3b4a4607e5
commit f14eb97e3c
9 changed files with 156 additions and 96 deletions

View File

@@ -4,14 +4,13 @@ package core
import (
"io"
"io/ioutil"
"os"
"strings"
"github.com/golang/protobuf/proto"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/cmdarg"
"v2ray.com/core/main/confloader"
)
// ConfigFormat is a configurable format of V2Ray config file.
@@ -90,18 +89,10 @@ func init() {
Loader: func(input interface{}) (*Config, error) {
switch v := input.(type) {
case cmdarg.Arg:
if len(v) == 0 {
return nil, newError("input has no element")
}
var data []byte
var rerr error
// pb type can only handle the first config
if v[0] == "stdin:" {
data, rerr = buf.ReadAllToBytes(os.Stdin)
} else {
data, rerr = ioutil.ReadFile(v[0])
}
common.Must(rerr)
r, err := confloader.LoadConfig(v[0])
common.Must(err)
data, err := buf.ReadAllToBytes(r)
common.Must(err)
return loadProtobufConfig(data)
case io.Reader:
data, err := buf.ReadAllToBytes(v)