domain

package
v0.0.0-...-66ceba8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 4 Imported by: 17

Documentation

Overview

Package domain provide functions to parse and handle domain names and labels.

Index

Constants

View Source
const (
	// MaxName is maximum number of bytes for whole domain name.
	MaxName = 255
	// MaxLabels is maximum number of labels domain name can consist of.
	MaxLabels = MaxName / 2
	// MaxLabel is maximim number of bytes for single label.
	MaxLabel = 63
)

Variables

View Source
var (
	// ErrTooManyLabels is returned for domain name with more than 127 labels.
	ErrTooManyLabels = errors.New("too many labels")
	// ErrEmptyLabel indicates that domain name contains empty label.
	ErrEmptyLabel = errors.New("empty label")
	// ErrLabelTooLong is returned when one of domain labels has more than 63 characters.
	ErrLabelTooLong = errors.New("label too long")
	// ErrNameTooLong is returned when domain name has more than 255 characters.
	ErrNameTooLong = errors.New("name too long")
	// ErrInvalidEscape is returned for invalid escape sequence.
	ErrInvalidEscape = errors.New("invalid escape sequence")
)

Functions

func MakeHumanReadableLabel

func MakeHumanReadableLabel(s string) string

MakeHumanReadableLabel makes human-readable label by escaping according RFC-4343.

func MakeLabel

func MakeLabel(s string) (string, error)

MakeLabel makes uppercase domain label from given human-readable representation. Ignores ending dot.

Types

type Name

type Name struct {
	// contains filtered or unexported fields
}

Name is a structure which represents domain name.

func MakeNameFromReflection

func MakeNameFromReflection(v reflect.Value) Name

MakeNameFromReflection extracts domain name from value. The value should wrap Name or *Name otherwise MakeNameFromReflection panics.

func MakeNameFromString

func MakeNameFromString(s string) (Name, error)

MakeNameFromString creates a Name from human-readable domain name string.

func (Name) GetLabel

func (n Name) GetLabel(off int) (string, int)

GetLabel returns label starting from given offset and offset of the next label. The method returns zero offset for the last label and -1 in case of error.

func (Name) GetLabels

func (n Name) GetLabels(f func(string) error) error

GetLabels iterate through name labels in reversed order.

func (Name) String

func (n Name) String() string

String method returns domain name in human-readable format.

Jump to

Keyboard shortcuts

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