mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
support include other config file
This commit is contained in:
parent
dc29da8c3c
commit
5286dfa244
34
conf/node.go
34
conf/node.go
@ -1,7 +1,11 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/InazumaV/V2bX/common/json5"
|
||||
"github.com/goccy/go-json"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type NodeConfig struct {
|
||||
@ -10,8 +14,9 @@ type NodeConfig struct {
|
||||
}
|
||||
|
||||
type rawNodeConfig struct {
|
||||
ApiRaw json.RawMessage `json:"ApiConfig"`
|
||||
OptRaw json.RawMessage `json:"Options"`
|
||||
Include string `json:"Include"`
|
||||
ApiRaw json.RawMessage `json:"ApiConfig"`
|
||||
OptRaw json.RawMessage `json:"Options"`
|
||||
}
|
||||
|
||||
type ApiConfig struct {
|
||||
@ -24,17 +29,30 @@ type ApiConfig struct {
|
||||
}
|
||||
|
||||
func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
||||
r := rawNodeConfig{}
|
||||
err = json.Unmarshal(data, &r)
|
||||
rn := rawNodeConfig{}
|
||||
err = json.Unmarshal(data, &rn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rn.Include) != 0 {
|
||||
f, err := os.Open(rn.Include)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open include file error: %s", err)
|
||||
}
|
||||
defer f.Close()
|
||||
data, err = io.ReadAll(json5.NewTrimNodeReader(f))
|
||||
err = json.Unmarshal(data, &rn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal include file error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
n.ApiConfig = ApiConfig{
|
||||
APIHost: "http://127.0.0.1",
|
||||
Timeout: 30,
|
||||
}
|
||||
if len(r.ApiRaw) > 0 {
|
||||
err = json.Unmarshal(r.ApiRaw, &n.ApiConfig)
|
||||
if len(rn.ApiRaw) > 0 {
|
||||
err = json.Unmarshal(rn.ApiRaw, &n.ApiConfig)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -50,8 +68,8 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
||||
SendIP: "0.0.0.0",
|
||||
CertConfig: NewCertConfig(),
|
||||
}
|
||||
if len(r.OptRaw) > 0 {
|
||||
err = json.Unmarshal(r.OptRaw, &n.Options)
|
||||
if len(rn.OptRaw) > 0 {
|
||||
err = json.Unmarshal(rn.OptRaw, &n.Options)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -62,12 +62,16 @@
|
||||
"EnableProxyProtocol": false,
|
||||
// 开启 TCP Fast Open
|
||||
"EnableTFO": true,
|
||||
|
||||
// 设置 Domain Strategy
|
||||
// 可选 prefer_ipv4 / prefer_ipv6 / ipv4_only / ipv6_only
|
||||
"DomainStrategy": "ipv4_only"
|
||||
|
||||
// More
|
||||
},
|
||||
{
|
||||
// 引用其他配置文件
|
||||
|
||||
"Include": "../example/config_node1.json"
|
||||
}
|
||||
/*,
|
||||
{
|
||||
|
13
example/config_node1.json
Normal file
13
example/config_node1.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"Core": "xray",
|
||||
"ApiHost": "https://127.0.0.1",
|
||||
"ApiKey": "key",
|
||||
"NodeID": 1,
|
||||
"NodeType": "vmess",
|
||||
"Timeout": 30,
|
||||
"ListenIP": "0.0.0.0",
|
||||
"SendIP": "0.0.0.0",
|
||||
"EnableProxyProtocol": false,
|
||||
"EnableTFO": true,
|
||||
"DomainStrategy": "ipv4_only"
|
||||
}
|
Loading…
Reference in New Issue
Block a user