platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
48
selective-vpn-api/app/routes_cache_helpers_files.go
Normal file
48
selective-vpn-api/app/routes_cache_helpers_files.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func writeLinesFile(path string, lines []string) error {
|
||||
if len(lines) == 0 {
|
||||
return os.WriteFile(path, []byte{}, 0o644)
|
||||
}
|
||||
payload := strings.Join(lines, "\n")
|
||||
if !strings.HasSuffix(payload, "\n") {
|
||||
payload += "\n"
|
||||
}
|
||||
return os.WriteFile(path, []byte(payload), 0o644)
|
||||
}
|
||||
|
||||
func readLinesFile(path string) ([]string, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lines := make([]string, 0, 64)
|
||||
for _, raw := range strings.Split(string(data), "\n") {
|
||||
ln := strings.TrimSpace(raw)
|
||||
if ln == "" {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, ln)
|
||||
}
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func cacheCopyOrEmpty(src, dst string) error {
|
||||
if err := copyFile(src, dst); err == nil {
|
||||
return nil
|
||||
}
|
||||
return os.WriteFile(dst, []byte{}, 0o644)
|
||||
}
|
||||
|
||||
func fileExists(path string) bool {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
||||
Reference in New Issue
Block a user