dnsctx

package
v0.6.83 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

package dnsctx helps with setting and getting data from the context of the current query. See the Match function source for what types are currently supported. When adding something to the context there is no check done on the type to not slow down the handler.

Index

Constants

View Source
const KeyStatus = "status"

Predefined context keys.

Variables

This section is empty.

Functions

func Addr added in v0.6.4

func Addr(ctx context.Context, key string) netip.Addr

Addr returns a netip.Addr from the context.

func Funcs

func Funcs(ctx context.Context, m *dns.Msg) *dns.Msg

Funcs iterates over all functions that are set in the context over the message. The possibly modified message is returned.

func Id added in v0.6.6

func Id(ctx context.Context) slog.Attr

Id returns a slog.Attr that either is empty or contains the request id as added by the id handler.

func Key added in v0.5.33

func Key(handler Keyer, key string) string

Key creates a key from the keyer and string.

func Match added in v0.5.27

func Match(ctx context.Context, key string, values []any) bool

Match checks the value under key and see if it matches any of the elements in the list. This function handles strings, string slices, ints, flaot64s, net.IPs and bools. A nil value for key returns true.

func Status added in v0.5.33

func Status(ctx context.Context, handler string) bool

Status returns boolean indicating if handler/status is set. If not found false is returned.

func String added in v0.6.6

func String(ctx context.Context, key string) string

String returns a string from the context under key.

func Valid added in v0.5.27

func Valid(key string) bool

Valid returns a boolean indicating if the key is a valid context key.

func Value

func Value(ctx context.Context, key string) any

Value returns the value under key. If key does not contain a slash nil is returned.

func WithFunc added in v0.5.27

func WithFunc(ctx context.Context, handler Keyer, f Func) context.Context

WithFunc appends the Func f in the context under the funcsKey. It is not possible to retrieve a specific Func. You can only run through them using Funcs.

func WithValue

func WithValue(ctx context.Context, key string, value any) context.Context

WithValue stores value under the string value key, key must contain a slash and be formatted like "<handler>/xxx". If key does not contain a slash, this function is noop.

Types

type Func

type Func func(*dns.Msg) *dns.Msg

Func is a function that can be set in the context and operates on a dns.Msg.

type Keyer added in v0.5.33

type Keyer interface {
	// Key returns the "key" of the handler.
	Key() string
}