spf

package
v0.69.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package spf provides types for building an SPF DNS TXT record.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatMechanism

func FormatMechanism(mechanism Mechanism) string

FormatMechanism formats a single mechanism as "<qualifier><name>:<value>" entries (space-separated when it has multiple values), e.g. "ip4:1.2.3.4".

func FormatMechanisms added in v0.45.1

func FormatMechanisms(mechanism ...Mechanism) string

FormatMechanisms formats each mechanism (see FormatMechanism) and joins the non-empty results with a space.

func IPMechanisms added in v0.45.1

func IPMechanisms(values ...string) (*Mechanism, *Mechanism)

IPMechanisms splits values (a mix of IPv4 and IPv6 addresses) into a separate "ip4" mechanism and "ip6" mechanism, either of which is nil if no addresses of that family were present.

Types

type Mechanism

type Mechanism struct {
	Qualifier  Qualifier           `mapstructure:"qualifier"`
	Name       string              `mapstructure:"name"`
	Values     []string            `mapstructure:"values"`
	ValueList  string              `mapstructure:"value-list"`
	ValuesFunc MechanismValuesFunc `json:"-"                  mapstructure:"-"`
}

Mechanism represents an SPF mechanism in a DNS record.

func AMechanism

func AMechanism(values ...string) Mechanism

AMechanism returns an "a" mechanism listing values.

func IP4Mechanism

func IP4Mechanism(values ...string) Mechanism

IP4Mechanism returns an "ip4" mechanism listing values.

func IP6Mechanism

func IP6Mechanism(values ...string) Mechanism

IP6Mechanism returns an "ip6" mechanism listing values.

func IncludeMechanism

func IncludeMechanism(values ...string) Mechanism

IncludeMechanism returns an "include" mechanism listing values.

func MXMechanism

func MXMechanism(values ...string) Mechanism

MXMechanism returns an "mx" mechanism listing values.

type MechanismValuesFunc

type MechanismValuesFunc func() []string

MechanismValuesFunc is a function type that returns mechanism values.

type Qualifier

type Qualifier string

Qualifier represents an SPF mechanism qualifier (e.g., "+", "-", "~", "?").

const (
	QualifierNone     Qualifier = ""
	QualifierPass     Qualifier = "+"
	QualifierSoftFail Qualifier = "~"
	QualifierFail     Qualifier = "-"
	QualifierNeutral  Qualifier = "?"
)

SPF mechanism qualifiers, per RFC 7208 section 4.6.1.

type Record

type Record struct {
	Version    string      `mapstructure:"version"`
	Mechanisms []Mechanism `mapstructure:"mechanisms"`

	All          bool      `mapstructure:"all"`
	AllQualifier Qualifier `mapstructure:"all-qualifier"`
}

Record represents an SPF DNS record.

func (*Record) Add

func (r *Record) Add(m Mechanism)

Add appends m to the record's mechanisms.

func (*Record) RecordPrefix

func (r *Record) RecordPrefix() string

RecordPrefix returns the DNS owner label prefix for an SPF record: always "" (the apex).

func (*Record) RecordType

func (r *Record) RecordType() string

RecordType returns the DNS record type string, "TXT".

func (*Record) RecordValue

func (r *Record) RecordValue() string

RecordValue returns the wire-ready, quoted SPF record value.

func (*Record) Render

func (r *Record) Render(data any) error

Render expands each mechanism's ValueList/Values templates against data.

func (*Record) String

func (r *Record) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL