package source import ( "fmt" "log/slog" "net/netip" ) // a simple source that returns the configured address. // useful when a record needs to have one specific value, // that is known in advance, and for debugging. type staticSource struct { log *slog.Logger addr netip.Addr } var _ Source = (*staticSource)(nil) func newStatic(log *slog.Logger, cfg Config) (*staticSource, error) { log = log.With("source", "static") addr, err := parse(cfg.Value, cfg.Family) if err != nil { log.Error( "static source can't be created from value", slog.String("family", string(cfg.Family)), slog.String("value", cfg.Value), ) return nil, fmt.Errorf("can't create static source from value: %w", err) } return &staticSource{log: log, addr: addr}, nil } func (s *staticSource) Supports(f Family) bool { return (s.addr.Is4() && f == IPv4) || (s.addr.Is6() && f == IPv6) } func (s *staticSource) Lookup(Family) (netip.Addr, error) { s.log.Info( "looked up address from static source", slog.String("addr", s.addr.String()), ) return s.addr, nil }