ip-ddns/config/domain.go

53 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-11-17 07:20:10 +01:00
package config
import "github.com/rs/zerolog"
// DomainDetails represents domain details.
type DomainDetails struct {
Name string `env:"NAME,notEmpty"`
Nameserver string `env:"NAMESERVER,notEmpty"`
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler.
func (d DomainDetails) MarshalZerologObject(e *zerolog.Event) {
e.
Str("name", d.Name).
Str("nameserver", d.Nameserver)
}
// EntryDetails represents DNS entry details.
type EntryDetails struct {
Domain string `env:"DN,notEmpty"`
Name string `env:"NAME,notEmpty"`
TTL uint16 `env:"TTL" envDefault:"60"`
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler.
func (d *EntryDetails) MarshalZerologObject(e *zerolog.Event) {
e.
Str("domain", d.Domain).
Str("name", d.Name).
Uint16("ttl", d.TTL)
}
// DomainConfig represents domain configuration.
type DomainConfig struct {
Source DomainDetails `envPrefix:"SRC_"`
Destination DomainDetails `envPrefix:"DST_"`
Entry EntryDetails `envPrefix:"ENTRY_"`
}
// MarshalZerologObject implements zerolog.LogObjectMarshaler.
func (c *DomainConfig) MarshalZerologObject(e *zerolog.Event) {
e.
Object("source", &c.Source).
Object("destination", &c.Destination).
Object("entry", &c.Entry)
}
var (
_ zerolog.LogObjectMarshaler = &DomainDetails{}
_ zerolog.LogObjectMarshaler = &EntryDetails{}
_ zerolog.LogObjectMarshaler = &DomainConfig{}
)