mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-19 01:14:58 +03:00
Invalid config check
This commit is contained in:
40
option/json.go
Normal file
40
option/json.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func ToMap(v any) (map[string]any, error) {
|
||||
bytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var content map[string]any
|
||||
err = json.Unmarshal(bytes, &content)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
|
||||
func MergeObjects(objects ...any) (map[string]any, error) {
|
||||
content := make(map[string]any)
|
||||
for _, object := range objects {
|
||||
objectMap, err := ToMap(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range objectMap {
|
||||
content[k] = v
|
||||
}
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
|
||||
func MarshallObjects(objects ...any) ([]byte, error) {
|
||||
content, err := MergeObjects(objects...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(content)
|
||||
}
|
||||
Reference in New Issue
Block a user