platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func applySingBoxRuntime(client TransportClient, restart bool) error {
|
||||
backend := selectTransportBackend(client)
|
||||
now := time.Now().UTC()
|
||||
|
||||
prov := backend.Provision(client)
|
||||
if !prov.OK {
|
||||
transportMu.Lock()
|
||||
st := loadTransportClientsState()
|
||||
if idx := findTransportClientIndex(st.Items, client.ID); idx >= 0 {
|
||||
it := st.Items[idx]
|
||||
applyTransportProvisionResult(&it, now, backend.ID(), prov)
|
||||
st.Items[idx] = it
|
||||
_ = saveTransportClientsState(st)
|
||||
}
|
||||
transportMu.Unlock()
|
||||
msg := strings.TrimSpace(prov.Message)
|
||||
if msg == "" {
|
||||
msg = "transport provision failed"
|
||||
}
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
action := "restart"
|
||||
if !restart {
|
||||
action = "start"
|
||||
}
|
||||
act := backend.Action(client, action)
|
||||
if !act.OK {
|
||||
transportMu.Lock()
|
||||
st := loadTransportClientsState()
|
||||
if idx := findTransportClientIndex(st.Items, client.ID); idx >= 0 {
|
||||
it := st.Items[idx]
|
||||
applyTransportLifecycleFailure(&it, action, now, backend.ID(), act)
|
||||
st.Items[idx] = it
|
||||
_ = saveTransportClientsState(st)
|
||||
}
|
||||
transportMu.Unlock()
|
||||
msg := strings.TrimSpace(act.Message)
|
||||
if msg == "" {
|
||||
msg = "transport action failed"
|
||||
}
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
probe := backend.Health(client)
|
||||
transportMu.Lock()
|
||||
st := loadTransportClientsState()
|
||||
if idx := findTransportClientIndex(st.Items, client.ID); idx >= 0 {
|
||||
it := st.Items[idx]
|
||||
applyTransportLifecycleAction(&it, action, now)
|
||||
it = applyTransportHealthProbeSnapshot(it, backend.ID(), probe, now)
|
||||
st.Items[idx] = it
|
||||
_ = saveTransportClientsState(st)
|
||||
}
|
||||
transportMu.Unlock()
|
||||
|
||||
if !probe.OK && normalizeTransportStatus(probe.Status) == TransportClientDown {
|
||||
msg := strings.TrimSpace(probe.Message)
|
||||
if msg == "" {
|
||||
msg = "transport health check failed"
|
||||
}
|
||||
return errors.New(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user