mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
support include http/https url
This commit is contained in:
24
conf/node.go
24
conf/node.go
@@ -2,11 +2,12 @@ package conf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/InazumaV/V2bX/common/json5"
|
"github.com/InazumaV/V2bX/common/json5"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeConfig struct {
|
type NodeConfig struct {
|
||||||
@@ -36,12 +37,29 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(rn.Include) != 0 {
|
if len(rn.Include) != 0 {
|
||||||
|
file, _ := strings.CutPrefix(rn.Include, ":")
|
||||||
|
switch file {
|
||||||
|
case "http", "https":
|
||||||
|
rsp, err := http.Get(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rsp.Body.Close()
|
||||||
|
data, err = io.ReadAll(json5.NewTrimNodeReader(rsp.Body))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open include file error: %s", err)
|
||||||
|
}
|
||||||
|
default:
|
||||||
f, err := os.Open(rn.Include)
|
f, err := os.Open(rn.Include)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open include file error: %s", err)
|
return fmt.Errorf("open include file error: %s", err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
data, err = io.ReadAll(json5.NewTrimNodeReader(f))
|
data, err = io.ReadAll(json5.NewTrimNodeReader(f))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open include file error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
err = json.Unmarshal(data, &rn)
|
err = json.Unmarshal(data, &rn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unmarshal include file error: %s", err)
|
return fmt.Errorf("unmarshal include file error: %s", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user