Files
elmprodvpn/selective-vpn-api/app/seeds.go
beckline 10a10f44a8 baseline: api+gui traffic mode + candidates picker
Snapshot before app-launcher (cgroup/mark) work; ignore binaries/backups.
2026-02-14 15:52:20 +03:00

48 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package app
import (
"fmt"
"io/fs"
"os"
)
// ---------------------------------------------------------------------
// seed-файлы и bootstrap
// ---------------------------------------------------------------------
// EN: Bootstrap seed files on first run so the API can start with sane defaults
// EN: even when runtime configuration files do not exist yet.
// RU: Инициализация seed-файлов при первом запуске, чтобы API стартовал
// RU: с корректными значениями по умолчанию при отсутствии runtime-конфигов.
// ---------------------------------------------------------------------
// seed initializer
// ---------------------------------------------------------------------
func ensureSeeds() {
_ = os.MkdirAll(domainDir, 0o755)
_ = os.MkdirAll("/etc/selective-vpn", 0o755)
_ = os.MkdirAll(stateDir, 0o755)
seedFile := func(name string, path string) {
if _, err := os.Stat(path); err == nil {
return
}
data, err := fs.ReadFile(embeddedDomains, "assets/domains/"+name)
if err != nil {
data = []byte{}
}
_ = os.WriteFile(path, data, 0o644)
}
seedFile("bases.txt", domainDir+"/bases.txt")
seedFile("subs.txt", domainDir+"/subs.txt")
seedFile("meta-special.txt", domainDir+"/meta-special.txt")
seedFile("static-ips.txt", staticIPsFile)
if _, err := os.Stat(dnsUpstreamsConf); err != nil {
content := fmt.Sprintf("default %s %s\nmeta %s %s\n", defaultDNS1, defaultDNS2, defaultMeta1, defaultMeta2)
_ = os.WriteFile(dnsUpstreamsConf, []byte(content), 0o644)
}
}