Initial commit
This commit is contained in:
commit
f57d355631
27 changed files with 1315 additions and 0 deletions
41
app/app.go
Normal file
41
app/app.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"dnsupdater/provider/manager"
|
||||
|
||||
"dnsupdater/ip"
|
||||
resolver "dnsupdater/ip/resolver"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
iplookup ip.NetInterfaceIPResolver
|
||||
|
||||
// Ip lookup service
|
||||
IPLookupService resolver.Service
|
||||
|
||||
// Updater manager
|
||||
ProviderManager *manager.Manager
|
||||
}
|
||||
|
||||
func NewApp(config *Config) (*App, error) {
|
||||
providerMgr := manager.New()
|
||||
// providerMgr.Register("digitalocean", digitalocean.New(config.Services.DigitalOcean.Token))
|
||||
err := providerMgr.RegisterFromConfig(config.Providers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l := resolver.Get(config.Services.IPLookup)
|
||||
|
||||
return &App{
|
||||
ProviderManager: providerMgr,
|
||||
IPLookupService: resolver.Get(config.Services.IPLookup),
|
||||
iplookup: ip.NewCache(resolver.LookupWrapper(l)).Get,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a App) GetIP(iface_name string) (net.IP, error) {
|
||||
return a.iplookup(iface_name)
|
||||
}
|
||||
47
app/config.go
Normal file
47
app/config.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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"`
|
||||
// DigitalOcean DigitalOceanService `yaml:"digitalocean"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Services Services `yaml:"services"`
|
||||
Providers map[string]map[string]interface{}
|
||||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue