better_template

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

better_template

An improved and simplified version of the coredns template plugin.

Usage:

Add the following to plugins.cfg, before debug:

better_template:github.com/nicelocal/better_template

And use the following example Corefile:

. {
    better_template {
        # Fallthrough to the next match block is always disabled for multiple matching blocks
        # Priority: exact > subdomain > domain > regexp > keyword
        #
        # Fallthrough to the next plugin is always disabled if at least one block matches

        example.com IN A { # Exact match
            answer "{{ .Name }} 60 IN A 192.168.1.1"
        }
        example.com IN AAAA { # Exact match
            answer "{{ .Name }} 60 IN AAAA ff::123"
        }

        subdomain:example.com { # Subdomains only match (matches *.example.com)
            [...]
        }
        domain:example.com { # Subdomains or domain match (matches example.com and *.example.com)
            [...]
        }
        regexp:exampl?e.com { # Regex match
            [...]
        }
        keyword:le.com { # Keyword match (domain contains)
            [...]
        }


        example.com ANY ANY { # Exact match, return nothing
        }
    }

    forward . 8.8.8.8
}

Example dockerfile:

FROM golang

RUN git clone -b v1.12.0 --depth 1 https://github.com/coredns/coredns /coredns && \
    cd /coredns && \
    sed '/bind:bind/a better_template:github.com/nicelocal/better_template' plugin.cfg -i && \
    make

FROM scratch

COPY --from=0 /coredns/coredns /coredns

ENTRYPOINT ["/coredns"]

Documentation

Overview

Package example is a CoreDNS plugin that prints "example" to stdout on every packet received.

It serves as an example CoreDNS plugin with numerous code comments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BetterTemplate

type BetterTemplate struct {
	Next plugin.Handler
	// contains filtered or unexported fields
}

func (*BetterTemplate) Name

func (e *BetterTemplate) Name() string

Name implements the Handler interface.

func (BetterTemplate) Ready

func (e BetterTemplate) Ready() bool

Ready implements the ready.Readiness interface, once this flips to true CoreDNS assumes this plugin is ready for queries; it is not checked again.

func (*BetterTemplate) ServeDNS

func (e *BetterTemplate) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface. This method gets called when example is used in a Server.

Jump to

Keyboard shortcuts

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