platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
42
selective-vpn-api/app/transport_tokens_state_policy_plan.go
Normal file
42
selective-vpn-api/app/transport_tokens_state_policy_plan.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func loadTransportPolicyCompilePlan() TransportPolicyCompilePlan {
|
||||
var plan TransportPolicyCompilePlan
|
||||
data, err := os.ReadFile(transportPolicyPlanStatePath)
|
||||
if err != nil {
|
||||
return plan
|
||||
}
|
||||
if err := json.Unmarshal(data, &plan); err != nil {
|
||||
return TransportPolicyCompilePlan{}
|
||||
}
|
||||
if plan.Interfaces == nil {
|
||||
plan.Interfaces = nil
|
||||
}
|
||||
return plan
|
||||
}
|
||||
|
||||
func saveTransportPolicyCompilePlan(plan TransportPolicyCompilePlan) error {
|
||||
if strings.TrimSpace(plan.GeneratedAt) == "" {
|
||||
plan.GeneratedAt = time.Now().UTC().Format(time.RFC3339)
|
||||
}
|
||||
data, err := json.MarshalIndent(plan, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(transportPolicyPlanStatePath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
tmp := transportPolicyPlanStatePath + ".tmp"
|
||||
if err := os.WriteFile(tmp, data, 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(tmp, transportPolicyPlanStatePath)
|
||||
}
|
||||
Reference in New Issue
Block a user