platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
51
selective-vpn-api/app/vpn_locations_cache.go
Normal file
51
selective-vpn-api/app/vpn_locations_cache.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
vpnLocationsCommandTimeout = 7 * time.Second
|
||||
vpnLocationsFreshTTL = 10 * time.Minute
|
||||
vpnLocationsBackoffMin = 2 * time.Second
|
||||
vpnLocationsBackoffMax = 60 * time.Second
|
||||
vpnLocationsCachePath = stateDir + "/vpn-locations-cache.json"
|
||||
)
|
||||
|
||||
type vpnLocationItem struct {
|
||||
Label string `json:"label"`
|
||||
ISO string `json:"iso"`
|
||||
Target string `json:"target,omitempty"`
|
||||
}
|
||||
|
||||
type vpnLocationsSnapshot struct {
|
||||
Locations []vpnLocationItem `json:"locations"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
Stale bool `json:"stale"`
|
||||
RefreshInProgress bool `json:"refresh_in_progress"`
|
||||
LastError string `json:"last_error,omitempty"`
|
||||
NextRetryAt string `json:"next_retry_at,omitempty"`
|
||||
}
|
||||
|
||||
type vpnLocationsCacheDisk struct {
|
||||
Locations []vpnLocationItem `json:"locations"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
type vpnLocationsStore struct {
|
||||
mu sync.Mutex
|
||||
|
||||
loaded bool
|
||||
|
||||
locations []vpnLocationItem
|
||||
swr refreshCoordinator
|
||||
}
|
||||
|
||||
var vpnLocationCache = &vpnLocationsStore{
|
||||
swr: newRefreshCoordinator(
|
||||
vpnLocationsFreshTTL,
|
||||
vpnLocationsBackoffMin,
|
||||
vpnLocationsBackoffMax,
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user