network

package
v0.0.0-...-6216d25 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 16 Imported by: 4

Documentation

Overview

Package network offers various network tools

Package network offers various network tools

Package network offers various network tools

Package network offers various network tools

Package network offers various network tools

Package network offers various network tools

Package network offers various network tools

Index

Constants

View Source
const AppName string = "goBlue/net"

AppName is the name of the application

FullVersion contains the full name and version of this package in a printable string

View Source
const VersionBuild string = "s"

VersionBuild is the type of this release. s(table), b(eta), d(evelopment), n(ightly)

View Source
const VersionMajor string = "0"

VersionMajor 0 means in development, >1 ensures compatibility with each minor version, but breakes with new major version

View Source
const VersionMinor string = "3"

VersionMinor introduces changes that require a new version number. If the major version is 0, they are likely to break compatibility

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	TargetIP, TargetPort string
	Connection           *net.Conn
	Reader               *bufio.Reader
}

Client is a simple network socketclient

func (*Client) Close

func (c *Client) Close() (err error)

Close closes the client

func (*Client) Connect

func (c *Client) Connect(ip string, port string) (err error)

Connect connects to ip + port

func (*Client) Recv

func (c *Client) Recv() (msg string, err error)

Recv waits and receives messages. BLOCKING

func (*Client) Sendln

func (c *Client) Sendln(msg string)

Sendln sends a message

type DSJSONData

type DSJSONData struct {
	ID         string      `json:"id"`
	Attributes interface{} `json:"attributes"`
	Type       string      `json:"type"`
}

DSJSONData has the actual information

type DSJSONError

type DSJSONError struct {
	Code   int    `json:"code"`
	Source string `json:"source"`
	Detail string `json:"detail"`
}

DSJSONError is a single error

type DSJSONErrors

type DSJSONErrors struct {
	Errs []DSJSONError `json:"errors"`
}

DSJSONErrors is an error container

type DSJSONResponse

type DSJSONResponse struct {
	Data []DSJSONData `json:"data"`
}

DSJSONResponse contains an array of DSJSONData

type DSJSONSingleResponse

type DSJSONSingleResponse struct {
	Data DSJSONData `json:"data"`
}

DSJSONSingleResponse contains a single data object

type DataServ

type DataServ struct {
	ServeMux *http.ServeMux
}

DataServ offers an api to serve function calls and/or json responses to http. Can also wrap a database-like structure to a http-api. Highly optimized for usage with ember-data and is likely to be removed from goBlue

func NewDataServ

func NewDataServ() *DataServ

NewDataServ creates a new Dataserver

func (*DataServ) Headers

func (ds *DataServ) Headers(rw http.ResponseWriter, req *http.Request)

Headers writes general headers

func (*DataServ) Register

func (ds *DataServ) Register(route string, jsr DSJSONResponse)

Register adds a route with a static response array on any method

func (*DataServ) RegisterGetFunction

func (ds *DataServ) RegisterGetFunction(route string, fn DataServFunction)

RegisterGetFunction adds a route that invokes a function on any method

func (*DataServ) RegisterPostFunction

func (ds *DataServ) RegisterPostFunction(route string, fn DataServPostFunction)

RegisterPostFunction adds a route that invokes a function on POST returning an error on any other method

func (*DataServ) RegisterSingle

func (ds *DataServ) RegisterSingle(route string, jsr DSJSONSingleResponse)

RegisterSingle adds a route with a single static response on any method

func (*DataServ) RegisterSingleWithPatch

func (ds *DataServ) RegisterSingleWithPatch(route string, jsr DSJSONSingleResponse, fn DataServPatchFunction)

RegisterSingleWithPatch adds a route invoking a function on PATCH or returning a single static response on any other method

func (*DataServ) RegisterSingleWithPost

func (ds *DataServ) RegisterSingleWithPost(route string, jsr DSJSONSingleResponse, fn DataServPostFunction)

RegisterSingleWithPost adds a route that invokes a function on POST request with post form input or a single static response on any other method

func (*DataServ) RegisterWithPatch

func (ds *DataServ) RegisterWithPatch(route string, jsr DSJSONResponse, fn DataServPatchFunction)

RegisterWithPatch adds a route invoking a function on PATCH or returning a static response array on any other method

func (*DataServ) RegisterWithPost

func (ds *DataServ) RegisterWithPost(route string, jsr DSJSONResponse, fn DataServPostFunction)

RegisterWithPost adds a route that invokes a function on POST request with post form input or a static response array on any other method

func (*DataServ) Start

func (ds *DataServ) Start(host, port string)

Start starts the http listener on host:port

type DataServFunction

type DataServFunction func() error

DataServFunction is a simple function thats called on get request

type DataServPatchFunction

type DataServPatchFunction func(*io.ReadCloser) error

DataServPatchFunction is a function thats called on patch request

type DataServPostFunction

type DataServPostFunction func(url.Values) error

DataServPostFunction is a function thats called on post request taking input

type Event

type Event struct {
	ID      string
	Name    string
	Payload string
}

Event contains information about a single event

type EventStream

type EventStream struct {
	EventQueue chan Event
	// contains filtered or unexported fields
}

EventStream contains a channel with events

type EventsourceClient

type EventsourceClient struct {
	Stream *EventStream
}

EventsourceClient is a simple Client for Eventsource streams

func (*EventsourceClient) Close

func (ec *EventsourceClient) Close()

Close closes the stream

func (*EventsourceClient) Subscribe

func (ec *EventsourceClient) Subscribe(url string) (*EventStream, error)

Subscribe subscribes to the given Eventsource-Server URL

type JSONAPIClient

type JSONAPIClient struct {
}

JSONAPIClient offers a simple json api client interface

func (*JSONAPIClient) Delete

func (jac *JSONAPIClient) Delete(url string, header map[string]string, response interface{}) (*JSONError, error)

Delete calls url with DELETE and sets header. Tries to parse response into any struct, returns jsonerror if request returned one or error on internal errors

func (*JSONAPIClient) Post

func (jac *JSONAPIClient) Post(url string, header map[string]string, data interface{}, response interface{}) (*JSONError, error)

Post calls url with POST with given data and sets header. Tries to parse response into any struct, returns jsonerror if request returned one or error on internal errors

func (*JSONAPIClient) Put

func (jac *JSONAPIClient) Put(url string, header map[string]string, data interface{}, response interface{}) (*JSONError, error)

Put calls url with PUT with given data and sets header. Tries to parse response into any struct, returns jsonerror if request returned one or error on internal errors

func (*JSONAPIClient) Request

func (jac *JSONAPIClient) Request(url string, header map[string]string, response interface{}) (*JSONError, error)

Request calls url with GET and sets header. Tries to parse response into any struct, returns jsonerror if request returned one or error on internal errors

type JSONError

type JSONError struct {
	Error   string `json:"error"`
	Status  int    `json:"status"`
	Message string `json:"message"`
}

JSONError contains a simple JSON error message

func (*JSONError) String

func (jso *JSONError) String() string

String converts a json error to pretty loggable/printable string

type Server

type Server struct {
	Address, Port string
	// contains filtered or unexported fields
}

Server is a simple socketserver. Not doing anything, pretty useless atm. Seriously.

func (*Server) Create

func (s *Server) Create(address, port string)

Create starts a echoserver on address:port. probably.

type Tokenbucket

type Tokenbucket struct {
	Limiter *rate.Limiter
}

Tokenbucket implements a simple Tokenbucket ratelimiter

func NewTokenbucket

func NewTokenbucket(refill time.Duration, tokens int) *Tokenbucket

NewTokenbucket creates a new Tokenbucket

func (*Tokenbucket) Wait

func (t *Tokenbucket) Wait() error

Wait waits until a token can be used

func (*Tokenbucket) WaitUntil

func (t *Tokenbucket) WaitUntil(ctx context.Context) error

WaitUntil waits until the context is canceled or a token can be used

Jump to

Keyboard shortcuts

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