Skip to content

Commit

Permalink
fix: changedir, new: add support of partial singbox configs
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 10, 2024
1 parent f84cecd commit 61a7c0f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var configByte []byte

func ParseConfig(path string, debug bool) ([]byte, error) {
content, err := os.ReadFile(path)
os.Chdir(filepath.Dir(path))
if err != nil {
return nil, err
}
Expand All @@ -31,7 +32,16 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
jsonDecoder := json.NewDecoder(SJ.NewCommentFilter(bytes.NewReader(content)))
if err := jsonDecoder.Decode(&jsonObj); err == nil {
if jsonObj["outbounds"] == nil {
return nil, fmt.Errorf("[SingboxParser] no outbounds found")
if jsonArray, ok := jsonObj.([]map[string]interface{}); ok {
jsonObj = map[string]interface{}{"outbounds": jsonArray}
if jsonArray[0]["type"] == nil {
return nil, fmt.Errorf("[SingboxParser] no outbounds found")
}
} else if jsonObj["type"] == nil {
return nil, fmt.Errorf("[SingboxParser] no outbounds found")
} else {
jsonObj = map[string]interface{}{"outbounds": []interface{}{jsonObj}}
}
}

jsonObj = map[string]interface{}{
Expand Down

0 comments on commit 61a7c0f

Please # to comment.