Files
elmprodvpn/selective-vpn-api/app/api_bootstrap.go

39 lines
907 B
Go

package app
import (
"context"
"errors"
"log"
"net/http"
appbootstrap "selective-vpn-api/app/bootstrap"
"time"
)
func runAPIServerAtAddr(addr string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
prepareAPIRuntime()
log.Printf("selective-vpn API listening on %s", addr)
if err := appbootstrap.Run(ctx, appbootstrap.Config{
Addr: addr,
ReadHeaderTimeout: 5 * time.Second,
RegisterRoutes: registerAPIRoutes,
WrapHandler: logRequests,
StartWatchers: startWatchers,
}); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("server error: %v", err)
}
}
func prepareAPIRuntime() {
ensureSeeds()
if err := ensureAppMarksNft(); err != nil {
log.Printf("traffic appmarks nft init warning: %v", err)
}
if err := restoreAppMarksFromState(); err != nil {
log.Printf("traffic appmarks restore warning: %v", err)
}
}