update-ip/provider.go

40 lines
709 B
Go
Raw Normal View History

2024-07-24 15:38:56 +02:00
package updateip
import (
"errors"
"fmt"
"net"
"strings"
"time"
log "github.com/sirupsen/logrus"
)
const DefaultTTL = 5 * time.Minute
type Provider interface {
UpdateIP(domain, name string, ip net.IP) error
}
func NewProvider(config *ProviderConfig) (Provider, error) {
if config == nil {
return nil, errors.New("provider: config is nil")
}
if config.Type == "" {
config.Type = config.Name
}
log.WithFields(log.Fields{
"name": config.Name,
"type": config.Type,
}).Debug("configuring provider")
switch strings.ToLower(config.Type) {
case "transip":
return NewTransIP(config)
default:
return nil, fmt.Errorf("provider %s: unsupported type %q", config.Name, config.Type)
}
}