1
0
Fork 0
mirror of https://gitlab.com/pnx-tools/dns-updater.git synced 2026-06-16 05:54:56 +02:00

fix unix line endings

This commit is contained in:
Henrik Hautakoski 2026-02-19 10:37:42 +01:00
parent b53e0bb9c7
commit c955b3ee3c
24 changed files with 1044 additions and 1044 deletions

View file

@ -1,59 +1,59 @@
package app
import (
"context"
"fmt"
"net"
"time"
dnsservice "dnsupdater/dns/service"
"dnsupdater/ip"
"dnsupdater/ip/resolver"
)
// WAN_IFACE Name for the virtual WAN interface
const WAN_IFACE = "wan"
type App struct {
cache *ip.Cache
cacheDefaultCallback ip.CacheDefaultCallback
// DNS service manager
DnsServiceMgr *dnsservice.Manager
}
func makeCacheCallback(service resolver.Service) ip.CacheDefaultCallback {
return func(name string) (net.IP, error) {
if name == WAN_IFACE {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
return service.Lookup(ctx)
}
return ip.GetInterfaceIP(name)
}
}
func NewApp(config *Config) (*App, error) {
dnsServiceMgr := dnsservice.NewManager()
err := dnsServiceMgr.RegisterFromConfig(config.Providers)
if err != nil {
return nil, err
}
ipService := resolver.Get(config.Services.IPLookup)
if ipService == nil {
return nil, fmt.Errorf("failed to load lookup service: %s", config.Services.IPLookup)
}
return &App{
DnsServiceMgr: dnsServiceMgr,
cache: ip.NewCache(),
cacheDefaultCallback: makeCacheCallback(ipService),
}, nil
}
func (a App) GetIP(iface_name string) (net.IP, error) {
return a.cache.GetWithDefault(iface_name, a.cacheDefaultCallback)
}
package app
import (
"context"
"fmt"
"net"
"time"
dnsservice "dnsupdater/dns/service"
"dnsupdater/ip"
"dnsupdater/ip/resolver"
)
// WAN_IFACE Name for the virtual WAN interface
const WAN_IFACE = "wan"
type App struct {
cache *ip.Cache
cacheDefaultCallback ip.CacheDefaultCallback
// DNS service manager
DnsServiceMgr *dnsservice.Manager
}
func makeCacheCallback(service resolver.Service) ip.CacheDefaultCallback {
return func(name string) (net.IP, error) {
if name == WAN_IFACE {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
return service.Lookup(ctx)
}
return ip.GetInterfaceIP(name)
}
}
func NewApp(config *Config) (*App, error) {
dnsServiceMgr := dnsservice.NewManager()
err := dnsServiceMgr.RegisterFromConfig(config.Providers)
if err != nil {
return nil, err
}
ipService := resolver.Get(config.Services.IPLookup)
if ipService == nil {
return nil, fmt.Errorf("failed to load lookup service: %s", config.Services.IPLookup)
}
return &App{
DnsServiceMgr: dnsServiceMgr,
cache: ip.NewCache(),
cacheDefaultCallback: makeCacheCallback(ipService),
}, nil
}
func (a App) GetIP(iface_name string) (net.IP, error) {
return a.cache.GetWithDefault(iface_name, a.cacheDefaultCallback)
}

View file

@ -1,46 +1,46 @@
package app
import (
"os"
"gopkg.in/yaml.v3"
)
type (
DomainRecords map[string]string
Domain map[string]DomainRecords
)
type DigitalOceanService struct {
Token string `yaml:"token"`
Domains map[string]DomainRecords `yaml:"domains"`
}
type Providers struct {
Token string `yaml:"token"`
Domains map[string]DomainRecords `yaml:"domains"`
}
type Services struct {
IPLookup string `yaml:"IPLookup"`
}
type Config struct {
Services Services `yaml:"services"`
Providers map[string]map[string]any
Updates map[string]Domain
}
func LoadConfig(filename string) (*Config, error) {
cfg := Config{
Services: Services{
IPLookup: "ipecho",
},
}
data, err := os.ReadFile(filename)
if err == nil {
err = yaml.Unmarshal(data, &cfg)
}
return &cfg, err
}
package app
import (
"os"
"gopkg.in/yaml.v3"
)
type (
DomainRecords map[string]string
Domain map[string]DomainRecords
)
type DigitalOceanService struct {
Token string `yaml:"token"`
Domains map[string]DomainRecords `yaml:"domains"`
}
type Providers struct {
Token string `yaml:"token"`
Domains map[string]DomainRecords `yaml:"domains"`
}
type Services struct {
IPLookup string `yaml:"IPLookup"`
}
type Config struct {
Services Services `yaml:"services"`
Providers map[string]map[string]any
Updates map[string]Domain
}
func LoadConfig(filename string) (*Config, error) {
cfg := Config{
Services: Services{
IPLookup: "ipecho",
},
}
data, err := os.ReadFile(filename)
if err == nil {
err = yaml.Unmarshal(data, &cfg)
}
return &cfg, err
}