Add http/block outbound & Improve route

This commit is contained in:
世界
2022-07-03 23:23:18 +08:00
parent 18e3f43df3
commit 4fc4eb09b0
25 changed files with 408 additions and 201 deletions

View File

@@ -5,6 +5,8 @@ import (
"github.com/goccy/go-json"
"github.com/sagernet/sing-box/common/badjson"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
)
func ToMap(v any) (*badjson.JSONObject, error) {
@@ -33,6 +35,12 @@ func MergeObjects(objects ...any) (*badjson.JSONObject, error) {
}
func MarshallObjects(objects ...any) ([]byte, error) {
objects = common.Filter(objects, func(v any) bool {
return v != nil
})
if len(objects) == 1 {
return json.Marshal(objects[0])
}
content, err := MergeObjects(objects...)
if err != nil {
return nil, err
@@ -53,6 +61,12 @@ func UnmarshallExcluded(inputContent []byte, parentObject any, object any) error
for _, key := range parentContent.Keys() {
content.Remove(key)
}
if object == nil {
if content.IsEmpty() {
return nil
}
return E.New("unexpected key: ", content.Keys()[0])
}
inputContent, err = content.MarshalJSON()
if err != nil {
return err