converters

package
v0.0.0-...-dd8c8ad Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Converters = map[uint16]func(data []string) (models.RecordValue, error){
	dns.TypeNS: func(data []string) (models.RecordValue, error) {
		if len(data) != 1 {
			return nil, ErrInvalidSegmentCount
		}
		return &models.NS{Ns: data[0]}, nil
	},
	dns.TypeA: func(data []string) (models.RecordValue, error) {
		if len(data) != 1 {
			return nil, ErrInvalidSegmentCount
		}
		ip := net.ParseIP(data[0])
		if ip.To4() == nil {
			return nil, errors.New("invalid IPv4 address")
		}
		return &models.A{IP: ip}, nil
	},
	dns.TypeAAAA: func(data []string) (models.RecordValue, error) {
		if len(data) != 1 {
			return nil, ErrInvalidSegmentCount
		}
		ip := net.ParseIP(data[0])
		if ip.To16() == nil {
			return nil, errors.New("invalid IPv6 address")
		}
		return &models.AAAA{IP: ip}, nil
	},
	dns.TypeTXT: func(data []string) (models.RecordValue, error) {
		return &models.TXT{Value: data[0]}, nil
	},
	dns.TypeCNAME: func(data []string) (models.RecordValue, error) {
		if len(data) != 1 {
			return nil, ErrInvalidSegmentCount
		}
		return &models.CNAME{Target: data[0]}, nil
	},
	dns.TypeMX: func(data []string) (models.RecordValue, error) {
		preference, err := strconv.ParseUint(data[0], 10, 16)
		if err != nil {
			return nil, err
		}
		return &models.MX{
			Preference: uint16(preference),
			Mx:         data[1],
		}, nil
	},
	dns.TypeSRV: func(data []string) (models.RecordValue, error) {
		if len(data) != 4 {
			return nil, ErrInvalidSegmentCount
		}
		priority, err := strconv.ParseUint(data[0], 10, 16)
		if err != nil {
			return nil, err
		}
		weight, err := strconv.ParseUint(data[1], 10, 16)
		if err != nil {
			return nil, err
		}
		port, err := strconv.ParseUint(data[2], 10, 16)
		if err != nil {
			return nil, err
		}
		return &models.SRV{
			Priority: uint16(priority),
			Weight:   uint16(weight),
			Port:     uint16(port),
			Target:   data[3],
		}, nil
	},
}
View Source
var ErrInvalidSegmentCount = errors.New("invalid segment count")

Functions

This section is empty.

Types

type ErrInvalidRecord

type ErrInvalidRecord struct {
	Name   string
	Value  string
	AType  string
	Reason error
}

func (ErrInvalidRecord) Error

func (e ErrInvalidRecord) Error() string

func (ErrInvalidRecord) Unwrap

func (e ErrInvalidRecord) Unwrap() error

Jump to

Keyboard shortcuts

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