platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
52
selective-vpn-api/app/transport_singbox_profiles_state.go
Normal file
52
selective-vpn-api/app/transport_singbox_profiles_state.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user