mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-02 06:48: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
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/InazumaV/V2bX/common/json5"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeConfig struct {
|
type NodeConfig struct {
|
||||||
@ -10,8 +14,9 @@ type NodeConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rawNodeConfig struct {
|
type rawNodeConfig struct {
|
||||||
ApiRaw json.RawMessage `json:"ApiConfig"`
|
Include string `json:"Include"`
|
||||||
OptRaw json.RawMessage `json:"Options"`
|
ApiRaw json.RawMessage `json:"ApiConfig"`
|
||||||
|
OptRaw json.RawMessage `json:"Options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiConfig struct {
|
type ApiConfig struct {
|
||||||
@ -24,17 +29,30 @@ type ApiConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
||||||
r := rawNodeConfig{}
|
rn := rawNodeConfig{}
|
||||||
err = json.Unmarshal(data, &r)
|
err = json.Unmarshal(data, &rn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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{
|
n.ApiConfig = ApiConfig{
|
||||||
APIHost: "http://127.0.0.1",
|
APIHost: "http://127.0.0.1",
|
||||||
Timeout: 30,
|
Timeout: 30,
|
||||||
}
|
}
|
||||||
if len(r.ApiRaw) > 0 {
|
if len(rn.ApiRaw) > 0 {
|
||||||
err = json.Unmarshal(r.ApiRaw, &n.ApiConfig)
|
err = json.Unmarshal(rn.ApiRaw, &n.ApiConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -50,8 +68,8 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
|||||||
SendIP: "0.0.0.0",
|
SendIP: "0.0.0.0",
|
||||||
CertConfig: NewCertConfig(),
|
CertConfig: NewCertConfig(),
|
||||||
}
|
}
|
||||||
if len(r.OptRaw) > 0 {
|
if len(rn.OptRaw) > 0 {
|
||||||
err = json.Unmarshal(r.OptRaw, &n.Options)
|
err = json.Unmarshal(rn.OptRaw, &n.Options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -62,12 +62,16 @@
|
|||||||
"EnableProxyProtocol": false,
|
"EnableProxyProtocol": false,
|
||||||
// 开启 TCP Fast Open
|
// 开启 TCP Fast Open
|
||||||
"EnableTFO": true,
|
"EnableTFO": true,
|
||||||
|
|
||||||
// 设置 Domain Strategy
|
// 设置 Domain Strategy
|
||||||
// 可选 prefer_ipv4 / prefer_ipv6 / ipv4_only / ipv6_only
|
// 可选 prefer_ipv4 / prefer_ipv6 / ipv4_only / ipv6_only
|
||||||
"DomainStrategy": "ipv4_only"
|
"DomainStrategy": "ipv4_only"
|
||||||
|
|
||||||
// More
|
// 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