platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
43
selective-vpn-api/app/egressutil/scope.go
Normal file
43
selective-vpn-api/app/egressutil/scope.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package egressutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ScopeTarget struct {
|
||||
Scope string
|
||||
Source string
|
||||
SourceID string
|
||||
}
|
||||
|
||||
func ParseScope(raw string, sanitizeID func(string) string) (ScopeTarget, error) {
|
||||
scope := strings.ToLower(strings.TrimSpace(raw))
|
||||
switch {
|
||||
case scope == "adguardvpn":
|
||||
return ScopeTarget{
|
||||
Scope: "adguardvpn",
|
||||
Source: "adguardvpn",
|
||||
}, nil
|
||||
case scope == "system":
|
||||
return ScopeTarget{
|
||||
Scope: "system",
|
||||
Source: "system",
|
||||
}, nil
|
||||
case strings.HasPrefix(scope, "transport:"):
|
||||
id := strings.TrimSpace(strings.TrimPrefix(scope, "transport:"))
|
||||
if sanitizeID != nil {
|
||||
id = sanitizeID(id)
|
||||
}
|
||||
if id == "" {
|
||||
return ScopeTarget{}, fmt.Errorf("invalid transport scope id")
|
||||
}
|
||||
return ScopeTarget{
|
||||
Scope: "transport:" + id,
|
||||
Source: "transport",
|
||||
SourceID: id,
|
||||
}, nil
|
||||
default:
|
||||
return ScopeTarget{}, fmt.Errorf("invalid scope, expected adguardvpn|system|transport:<id>")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user