platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
90
selective-vpn-api/app/entrypoints.go
Normal file
90
selective-vpn-api/app/entrypoints.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
appcli "selective-vpn-api/app/cli"
|
||||
)
|
||||
|
||||
// EN: Application entrypoint and process bootstrap.
|
||||
// EN: This file wires CLI modes and delegates API runtime bootstrap.
|
||||
// RU: Точка входа приложения и bootstrap процесса.
|
||||
// RU: Этот файл связывает CLI-режимы и делегирует запуск API-сервера.
|
||||
func Run() {
|
||||
if code, handled := runLegacyCLIMode(os.Args[1:]); handled {
|
||||
if code != 0 {
|
||||
os.Exit(code)
|
||||
}
|
||||
return
|
||||
}
|
||||
RunAPIServer()
|
||||
}
|
||||
|
||||
// RunAPIServer starts the HTTP/SSE API server mode.
|
||||
func RunAPIServer() {
|
||||
runAPIServerAtAddr("127.0.0.1:8080")
|
||||
}
|
||||
|
||||
// RunRoutesUpdateCLI executes one-shot routes update mode.
|
||||
func RunRoutesUpdateCLI(args []string) int {
|
||||
return appcli.RunRoutesUpdate(args, appcli.RoutesUpdateDeps{
|
||||
LockFile: lockFile,
|
||||
Update: func(iface string) (bool, string) {
|
||||
res := routesUpdate(iface)
|
||||
return res.OK, res.Message
|
||||
},
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stderr,
|
||||
})
|
||||
}
|
||||
|
||||
// RunRoutesClearCLI executes one-shot routes clear mode.
|
||||
func RunRoutesClearCLI(args []string) int {
|
||||
return appcli.RunRoutesClear(args, appcli.RoutesClearDeps{
|
||||
Clear: func() (bool, string) {
|
||||
res := routesClear()
|
||||
return res.OK, res.Message
|
||||
},
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stderr,
|
||||
})
|
||||
}
|
||||
|
||||
// RunAutoloopCLI executes autoloop mode.
|
||||
func RunAutoloopCLI(args []string) int {
|
||||
return appcli.RunAutoloop(args, appcli.AutoloopDeps{
|
||||
StateDirDefault: stateDir,
|
||||
ResolveIface: func(flagIface string) string {
|
||||
resolvedIface := normalizePreferredIface(flagIface)
|
||||
if resolvedIface == "" {
|
||||
resolvedIface, _ = resolveTrafficIface(loadTrafficModeState().PreferredIface)
|
||||
}
|
||||
return resolvedIface
|
||||
},
|
||||
Run: func(params appcli.AutoloopParams) {
|
||||
runAutoloop(
|
||||
params.Iface,
|
||||
params.Table,
|
||||
params.MTU,
|
||||
params.StateDir,
|
||||
params.DefaultLocation,
|
||||
)
|
||||
},
|
||||
Stderr: os.Stderr,
|
||||
})
|
||||
}
|
||||
|
||||
func runLegacyCLIMode(args []string) (int, bool) {
|
||||
if len(args) == 0 {
|
||||
return 0, false
|
||||
}
|
||||
switch args[0] {
|
||||
case "routes-update", "-routes-update":
|
||||
return RunRoutesUpdateCLI(args[1:]), true
|
||||
case "routes-clear":
|
||||
return RunRoutesClearCLI(args[1:]), true
|
||||
case "autoloop":
|
||||
return RunAutoloopCLI(args[1:]), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user