example

package module
v0.0.0-...-4d5a0c1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

example

Name

example - prints "example" after a query is handled.

Description

The example plugin prints "example" on every query that got handled by the server. It serves as documentation for writing CoreDNS plugins.

Compilation

This package will always be compiled as part of CoreDNS and not in a standalone way. It will require you to use go get or as a dependency on plugin.cfg.

The manual will have more information about how to configure and extend the server with external plugins.

A simple way to consume this plugin, is by adding the following on plugin.cfg, and recompile it as detailed on coredns.io.

example:github.com/coredns/example

Put this early in the plugin list, so that example is executed before any of the other plugins.

After this you can compile coredns by:

go generate
go build

Or you can instead use make:

make

Syntax

example

Metrics

If monitoring is enabled (via the prometheus directive) the following metric is exported:

  • coredns_example_request_count_total{server} - query count to the example plugin.

The server label indicated which server handled the request, see the metrics plugin for details.

Ready

This plugin reports readiness to the ready plugin. It will be immediately ready.

Examples

In this configuration, we forward all queries to 9.9.9.9 and print "example" whenever we receive a query.

. {
  forward . 9.9.9.9
  example
}

Or without any external connectivity:

. {
  whoami
  example
}

Also See

See the manual.

Documentation

Overview

Package example is a CoreDNS plugin that prints the DNS query and response to stdout on every packet received and resolves the A record of CNAME targets internally if needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Example

type Example struct {
	Next plugin.Handler
}

Example is an example plugin to show how to write a plugin.

func (Example) Name

func (e Example) Name() string

Name implements the Handler interface.

func (Example) Ready

func (e Example) 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 (Example) ServeDNS

func (e Example) 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.

type ResponsePrinter

type ResponsePrinter struct {
	dns.ResponseWriter
	// contains filtered or unexported fields
}

ResponsePrinter wraps a dns.ResponseWriter and logs the DNS response message. It also recursively resolves A records for CNAME responses if needed.

func NewResponsePrinter

func NewResponsePrinter(w dns.ResponseWriter, handler plugin.Handler) *ResponsePrinter

NewResponsePrinter returns a ResponsePrinter wrapping the original dns.ResponseWriter and plugin handler.

func (*ResponsePrinter) WriteMsg

func (r *ResponsePrinter) WriteMsg(res *dns.Msg) error

WriteMsg calls the underlying ResponseWriter's WriteMsg method and adds an A record if the response only contains a CNAME.

Jump to

Keyboard shortcuts

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