mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
41 lines
826 B
Go
41 lines
826 B
Go
package option
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/sagernet/sing/common/x/linkedhashmap"
|
|
)
|
|
|
|
func ToMap(v any) (*linkedhashmap.Map[string, any], error) {
|
|
bytes, err := json.Marshal(v)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var content linkedhashmap.Map[string, any]
|
|
err = json.Unmarshal(bytes, &content)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &content, nil
|
|
}
|
|
|
|
func MergeObjects(objects ...any) (*linkedhashmap.Map[string, any], error) {
|
|
var content linkedhashmap.Map[string, any]
|
|
for _, object := range objects {
|
|
objectMap, err := ToMap(object)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
content.PutAll(objectMap)
|
|
}
|
|
return &content, nil
|
|
}
|
|
|
|
func MarshallObjects(objects ...any) ([]byte, error) {
|
|
content, err := MergeObjects(objects...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(content)
|
|
}
|