tcpserver

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package tcpserver contains the tcp server logic

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallBackFunc added in v0.0.5

type CallBackFunc func(ctx context.Context, question []byte) (answer []byte, err error)

CallBackFunc handles what is send back to the client, based on the incomming question

type ContextType added in v0.0.5

type ContextType string

ContextType is the key type stored in ctx

var (
	// Addr is the contextKey where the net.Addr is stored
	Addr ContextType = "addr"
)

type Options

type Options struct {
	Listen      string
	TLS         bool
	Certificate string
	Key         string
	Domain      string

	Verbose bool
	// contains filtered or unexported fields
}

Options of the tcp server

type Rule

type Rule struct {
	Name          string `yaml:"name,omitempty"`
	Match         string `yaml:"match,omitempty"`
	MatchContains string `yaml:"match-contains,omitempty"`

	Response string `yaml:"response,omitempty"`
	// contains filtered or unexported fields
}

Rule to apply to various requests

func NewLiteralRule added in v0.0.5

func NewLiteralRule(match, response string) (*Rule, error)

NewLiteralRule returns a new literal-match Rule

func NewRegexRule added in v0.0.5

func NewRegexRule(match, response string) (*Rule, error)

NewRegexRule returns a new regex-match Rule

func NewRule

func NewRule(match, response string) (*Rule, error)

NewRule creates a new Rule - default is regex

func NewRuleFromTemplate added in v0.0.5

func NewRuleFromTemplate(r Rule) (newRule *Rule, err error)

NewRuleFromTemplate "copies" a new Rule

func (*Rule) MatchInput added in v0.0.5

func (r *Rule) MatchInput(input []byte) bool

MatchInput returns if the input was matches with one of the matchers

type RulesConfiguration

type RulesConfiguration struct {
	Rules []Rule `yaml:"rules"`
}

RulesConfiguration from yaml

type TCPServer

type TCPServer struct {

	// Callbacks to retrieve information about the system
	HandleMessageFnc CallBackFunc
	// contains filtered or unexported fields
}

TCPServer instance

func New

func New(options *Options) (*TCPServer, error)

New tcp server instance with specified options

func (*TCPServer) AddRule

func (t *TCPServer) AddRule(rule Rule) error

AddRule to the server

func (*TCPServer) BuildResponse

func (t *TCPServer) BuildResponse(data []byte) ([]byte, error)

BuildResponse according to rules

func (*TCPServer) BuildResponseWithContext added in v0.0.5

func (t *TCPServer) BuildResponseWithContext(ctx context.Context, data []byte) ([]byte, error)

BuildResponseWithContext is a wrapper with context

func (*TCPServer) BuildRuleResponse added in v0.0.5

func (t *TCPServer) BuildRuleResponse(ctx context.Context, data []byte) ([]byte, error)

BuildResponseWithContext is a wrapper with context

func (*TCPServer) Close

func (t *TCPServer) Close() error

Close the service

func (*TCPServer) ListenAndServe

func (t *TCPServer) ListenAndServe() error

ListenAndServe requests

func (*TCPServer) ListenAndServeTLS

func (t *TCPServer) ListenAndServeTLS() error

ListenAndServeTLS requests over tls

func (*TCPServer) LoadTemplate

func (t *TCPServer) LoadTemplate(templatePath string) error

LoadTemplate from yaml

func (*TCPServer) MatchRule added in v0.0.5

func (t *TCPServer) MatchRule(data []byte) (rule Rule, err error)

MatchRule returns the rule, which was matched first

Jump to

Keyboard shortcuts

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