net

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 8

Documentation

Overview

Package net provides additional network helper functions and in subpackages middleware.

Which http router should I use? CoreStore doesn't care because it uses the standard library http API. You can choose nearly any router you like.

TODO(CyS) consider the next items: - context Package: https://twitter.com/peterbourgon/status/752022730812317696 - Sessions: https://github.com/alexedwards/scs - Form decoding https://github.com/monoculum/formam - Kerberos github.com/jcmturner/gokrb5

Index

Constants

View Source
const (
	MethodHead    = `HEAD`
	MethodGet     = "GET"
	MethodPost    = "POST"
	MethodPut     = "PUT"
	MethodPatch   = "PATCH"
	MethodDelete  = "DELETE"
	MethodTrace   = "TRACE"
	MethodOptions = "OPTIONS"
)

Method* defines the available methods which this library supports

View Source
const (
	CONNECT = "CONNECT"
	DELETE  = "DELETE"
	GET     = "GET"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
	PATCH   = "PATCH"
	POST    = "POST"
	PUT     = "PUT"
	TRACE   = "TRACE"
)

HTTP methods

View Source
const (
	ApplicationForm                  = "application/x-www-form-urlencoded"
	ApplicationGob                   = "application/gob"
	ApplicationJSON                  = "application/json"
	ApplicationJSONCharsetUTF8       = ApplicationJSON + "; " + CharsetUTF8
	ApplicationJavaScript            = "application/javascript"
	ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8
	ApplicationMsgpack               = "application/msgpack"
	ApplicationProtobuf              = "application/protobuf"
	ApplicationXML                   = "application/xml"
	ApplicationXMLCharsetUTF8        = ApplicationXML + "; " + CharsetUTF8
	CompressDeflate                  = "deflate"
	CompressGZIP                     = "gzip"
	MultipartForm                    = "multipart/form-data"
	TextHTML                         = "text/html"
	TextHTMLCharsetUTF8              = TextHTML + "; " + CharsetUTF8
	TextPlain                        = "text/plain"
	TextPlainCharsetUTF8             = TextPlain + "; " + CharsetUTF8
)

Media types

View Source
const (
	AcceptEncoding     = "Accept-Encoding"
	Authorization      = "Authorization"
	ClientIP           = "Client-Ip"
	ContentDisposition = "Content-Disposition"
	ContentEncoding    = "Content-Encoding"
	ContentLength      = "Content-Length"
	ContentSignature   = "Content-Signature"
	ContentType        = "Content-Type"
	Forwarded          = "Forwarded"
	ForwardedFor       = "Forwarded-For"
	Location           = "Location"
	Trailer            = "Trailer"
	Upgrade            = "Upgrade"
	Vary               = "Vary"
	WWWAuthenticate    = "WWW-Authenticate"
	XClusterClientIP   = "X-Cluster-Client-Ip"
	XForwarded         = "X-Forwarded"
	XForwardedFor      = "X-Forwarded-For"
	XRealIP            = "X-Real-Ip"
)

Headers

View Source
const (
	CharsetUTF8 = "charset=utf-8"
)

Charset

View Source
const (
	WebSocket = "websocket"
)

Protocols

Variables

View Source
var PrivateIPRanges = IPRanges{
	MakeIPRange("10.0.0.0", "10.255.255.255"),
	MakeIPRange("100.64.0.0", "100.127.255.255"),
	MakeIPRange("172.16.0.0", "172.31.255.255"),
	MakeIPRange("192.0.0.0", "192.0.0.255"),
	MakeIPRange("192.168.0.0", "192.168.255.255"),
	MakeIPRange("198.18.0.0", "198.19.255.255"),
}

PrivateIPRanges defines a list of private IP subnets. Can be modified by yourself.

Functions

func ShiftPath

func ShiftPath(p string) (head, tail string)

ShiftPath splits off the first component of p, which will be cleaned of relative components before processing. `head` will never contain a slash and `tail` will always be a rooted path without trailing slash. Source: http://blog.merovius.de/2017/06/18/how-not-to-use-an-http-router.html

Types

type IPRange

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

IPRange contains a from and to IP address. v4 or v6 doesn't matter.

func MakeIPRange

func MakeIPRange(from, to string) IPRange

MakeIPRange creates a new instance.

func (IPRange) In

func (ir IPRange) In(test gonet.IP) bool

In checks if test IP lies within the range.

func (IPRange) InStr

func (ir IPRange) InStr(ip string) bool

InStr checks if the test IP address string lies within the range.

type IPRanges

type IPRanges []IPRange

IPRanges contains multiple IPRange entries. v4 or v6 doesn't matter.

func MakeIPRanges

func MakeIPRanges(fromTo ...string) IPRanges

MakeIPRanges creates a new instance. May return nil if imbalanced pairs are provided. IPv4 or IPv6 doesn't matter.

func (IPRanges) In

func (s IPRanges) In(test gonet.IP) bool

In checks if test IP lies within the ranges.

func (IPRanges) InStr

func (s IPRanges) InStr(ip string) bool

InStr checks if the test IP address string lies within the ranges.

func (IPRanges) Strings

func (s IPRanges) Strings() []string

Strings converts all IP addresses to a string slice.

Directories

Path Synopsis
backendauth
Package backendauth (TODO) defines the backend configuration options and element slices.
Package backendauth (TODO) defines the backend configuration options and element slices.
Package cors provides a middleware for Cross-origin resource sharing (CORS).
Package cors provides a middleware for Cross-origin resource sharing (CORS).
backendcors
Package backendcors defines the backend configuration options and element slices.
Package backendcors defines the backend configuration options and element slices.
Package csgrpc provides basics types for grpc servers and clients.
Package csgrpc provides basics types for grpc servers and clients.
auth
Package grpc_auth a generic server-side auth middleware for gRPC.
Package grpc_auth a generic server-side auth middleware for gRPC.
scope
Package grpc_scope handles setting and retrieving the store/scope for clients and servers.
Package grpc_scope handles setting and retrieving the store/scope for clients and servers.
Package csrf implements scope based Cross-Site Request Forgery protection.
Package csrf implements scope based Cross-Site Request Forgery protection.
Package geoip detects the country by an IP address and provides alternative handlers.
Package geoip detects the country by an IP address and provides alternative handlers.
backendgeoip
Package backendgeoip defines the backend configuration options and element slices.
Package backendgeoip defines the backend configuration options and element slices.
maxmindfile
Package maxmindfile provides an OptionFactoryFunc for the backendgeopip package.
Package maxmindfile provides an OptionFactoryFunc for the backendgeopip package.
maxmindwebservice
Package maxmindwebservice provides an OptionFactoryFunc for the backendgeopip package.
Package maxmindwebservice provides an OptionFactoryFunc for the backendgeopip package.
internal
scopedservice
Package scopedservice gets copied to specific net middleware packages - do not use.
Package scopedservice gets copied to specific net middleware packages - do not use.
jwt
Package jwt provides a middleware for JSON web token authentication and runMode initialization.
Package jwt provides a middleware for JSON web token authentication and runMode initialization.
backendjwt
Package backendjwt defines the backend configuration options and element slices.
Package backendjwt defines the backend configuration options and element slices.
Package mw provides a various middleware.
Package mw provides a various middleware.
Package problem implements the RFC7807 Details for HTTP APIs.
Package problem implements the RFC7807 Details for HTTP APIs.
Package ratelimit implements scope based HTTP rate limiting.
Package ratelimit implements scope based HTTP rate limiting.
Package request provides functions for http request handling.
Package request provides functions for http request handling.
Package response provides functions for working with an http response.
Package response provides functions for working with an http response.
Package responseproxy provides various proxy functions for extending http.ResponseWriter.
Package responseproxy provides various proxy functions for extending http.ResponseWriter.
Package runmode defines store specific middleware to initialize the scope and its ID per request.
Package runmode defines store specific middleware to initialize the scope and its ID per request.
Package secure adds a middleware for quick security wins to response HTTP headers
Package secure adds a middleware for quick security wins to response HTTP headers
Package signed provides a middleware to sign responses and validate requests.
Package signed provides a middleware to sign responses and validate requests.
Package url parses program specific URLs and provides helper functions.
Package url parses program specific URLs and provides helper functions.

Jump to

Keyboard shortcuts

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