server

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerClosed  = errors.New("server closed")
	ErrServerStarted = errors.New("server has been started")
)

Server errors

Functions

This section is empty.

Types

type Server

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

func NewServer

func NewServer(protocol, addr string, options ...ServerOption) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) Start

func (s *Server) Start() error

Start starts the udp server. Start always returns an non-nil err. After Close(), an ErrServerClosed will be returned.

type ServerOption

type ServerOption func(s *Server)

func WithCertificate

func WithCertificate(cert, key string) ServerOption

WithCertificate sets the certificate for DoT, DoH server. WithTLSConfig and WithCertificate cannot be omitted at the same time.

func WithHandler

func WithHandler(h dns_handler.Handler) ServerOption

WithHandler sets the dns handler for UDP, TCP, DoT server. It cannot be omitted.

func WithHttpHandler

func WithHttpHandler(h http.Handler) ServerOption

WithHttpHandler sets the http handler for DoH, HTTP server. It cannot be omitted.

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) ServerOption

WithIdleTimeout sets tcp, dot and doh connections idle timeout. Default is defaultIdleTimeout.

func WithListener

func WithListener(l net.Listener) ServerOption

WithListener sets the TCP listener for TCP, DoT, DoH server. With WithListener, addr in NewServer can be empty.

func WithLogger

func WithLogger(l *zap.Logger) ServerOption

func WithPacketConn

func WithPacketConn(c net.PacketConn) ServerOption

WithPacketConn sets the UDP socket UDP server. With WithPacketConn, addr in NewServer can be empty.

func WithQueryTimeout

func WithQueryTimeout(d time.Duration) ServerOption

WithQueryTimeout sets the query maximum executing time. Default is defaultQueryTimeout.

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ServerOption

WithTLSConfig sets the tls config for DoT, DoH server. WithTLSConfig and WithCertificate cannot be omitted at the same time.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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