platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
68
selective-vpn-api/app/routes_update_helpers_fs.go
Normal file
68
selective-vpn-api/app/routes_update_helpers_fs.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net"
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// filesystem helpers
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
func copyFile(src, dst string) error {
|
||||
data, err := os.ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(dst, data, 0o644)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `chownDev` contains core logic for chown dev.
|
||||
// RU: `chownDev` - содержит основную логику для chown dev.
|
||||
// ---------------------------------------------------------------------
|
||||
func chownDev(paths ...string) {
|
||||
usr, err := user.Lookup("dev")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uid, _ := strconv.Atoi(usr.Uid)
|
||||
gid, _ := strconv.Atoi(usr.Gid)
|
||||
for _, p := range paths {
|
||||
_ = os.Chown(p, uid, gid)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// EN: `chmodPaths` contains core logic for chmod paths.
|
||||
// RU: `chmodPaths` - содержит основную логику для chmod paths.
|
||||
// ---------------------------------------------------------------------
|
||||
func chmodPaths(mode fs.FileMode, paths ...string) {
|
||||
for _, p := range paths {
|
||||
_ = os.Chmod(p, mode)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// readiness helpers
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
func waitDNS(attempts int, delay time.Duration) error {
|
||||
target := "openai.com"
|
||||
for i := 0; i < attempts; i++ {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
_, err := net.DefaultResolver.LookupHost(ctx, target)
|
||||
cancel()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(delay)
|
||||
}
|
||||
return fmt.Errorf("dns lookup failed after %d attempts", attempts)
|
||||
}
|
||||
Reference in New Issue
Block a user