53 lines
954 B
Go
53 lines
954 B
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func normalizeSingBoxProfileMode(mode SingBoxProfileMode) (SingBoxProfileMode, bool) {
|
|
switch strings.ToLower(strings.TrimSpace(string(mode))) {
|
|
case "typed":
|
|
return SingBoxProfileModeTyped, true
|
|
case "raw":
|
|
return SingBoxProfileModeRaw, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
func normalizeSingBoxProtocol(v string) string {
|
|
return strings.ToLower(strings.TrimSpace(v))
|
|
}
|
|
|
|
func normalizeSingBoxSchemaVersion(v int) int {
|
|
if v <= 0 {
|
|
return 1
|
|
}
|
|
return v
|
|
}
|
|
|
|
func parseOptionalInt64(v string) (int64, error) {
|
|
s := strings.TrimSpace(v)
|
|
if s == "" {
|
|
return 0, nil
|
|
}
|
|
return strconv.ParseInt(s, 10, 64)
|
|
}
|
|
|
|
func cloneMapDeep(in map[string]any) map[string]any {
|
|
if in == nil {
|
|
return nil
|
|
}
|
|
b, err := json.Marshal(in)
|
|
if err != nil {
|
|
return cloneMap(in)
|
|
}
|
|
out := map[string]any{}
|
|
if err := json.Unmarshal(b, &out); err != nil {
|
|
return cloneMap(in)
|
|
}
|
|
return out
|
|
}
|