common

package
v0.0.0-...-237f4c2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Plain Text format Mime Type
	PLAIN_TEXT_MIME_TYPE MimeType = "text/plain"
	//Json format Mime Type
	JSON_MIME_TYPE MimeType = "application/json"
	//Xml format Mime Type
	XML_MIME_TYPE MimeType = "application/xml"
	//Yaml format Mime Type
	YAML_MIME_TYPE MimeType = "text/yaml"
	//Zip Archive format Mime Type
	ZIP_ARCHIVE_MIME_TYPE MimeType = "application/zip"
	//Binary Data format Mime Type
	BINARY_DATA_MIME_TYPE MimeType = "application/octet-stream"

	//Rest Web Method: GET
	REST_METHOD_GET RestMethod = http.MethodGet
	//Rest Web Method: POST
	REST_METHOD_POST RestMethod = http.MethodPost
	//Rest Web Method: POST (FORM)
	REST_METHOD_POST_FORM RestMethod = http.MethodPost + "_FORM"
	//Rest Web Method: HEAD
	REST_METHOD_HEAD RestMethod = http.MethodHead
	//Rest Web Method: CONNECT
	REST_METHOD_CONNECT RestMethod = http.MethodConnect
	//Rest Web Method: DELETE
	REST_METHOD_DELETE RestMethod = http.MethodDelete
	//Rest Web Method: OPTIONS
	REST_METHOD_OPTIONS RestMethod = http.MethodOptions
	//Rest Web Method: PATCH
	REST_METHOD_PATCH RestMethod = http.MethodPatch
	//Rest Web Method: PUT
	REST_METHOD_PUT RestMethod = http.MethodPut
	//Rest Web Method: TRACE
	REST_METHOD_TRACE RestMethod = http.MethodTrace

	//Rest Web Protocol: HTTP
	REST_PROTOCOL_HTTP RestProtocol = "http"
	//Rest Web Protocol: HTTPS
	REST_PROTOCOL_HTTPS RestProtocol = "https"
	//Rest Web Protocol: WS
	REST_PROTOCOL_WS RestProtocol = "ws"
)

Variables

View Source
var (
	// Session Context Key
	ContextSessionKey = ContextKey("session-key")
	// Session Context Auth Token
	ContextKeyAuthtoken = ContextKey("auth-token")
	// Session Context Remote Address
	ContextRemoteAddress = ContextKey("remote-address")
)

Functions

func AddressCount

func AddressCount(network *net.IPNet) uint64

AddressCount returns the number of distinct host addresses within the given CIDR range.

Since the result is a uint64, this function returns meaningful information only for IPv4 ranges and IPv6 ranges with a prefix size of at least 65.

func AddressRange

func AddressRange(network *net.IPNet) (net.IP, net.IP)

AddressRange returns the first and last addresses in the given CIDR range.

func Dec

func Dec(IP net.IP) net.IP

Dec decreases the IP by one this returns a new []byte for the IP

func GenerateSecureToken

func GenerateSecureToken(length int) string

Generate a Security Token of a given length

func Host

func Host(base *net.IPNet, num int) (net.IP, error)

Host takes a parent CIDR range and turns it into a host IP address with the given host number.

For example, 10.3.0.0/16 with a host number of 2 gives 10.3.0.2.

func Inc

func Inc(IP net.IP) net.IP

Inc increases the IP by one this returns a new []byte for the IP

func ListAddresses

func ListAddresses(network *net.IPNet) []net.IP

ListAddresses returns the list of all addresses in the given CIDR range.

func NextSubnet

func NextSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool)

NextSubnet returns the next available subnet of the desired mask size starting for the maximum IP of the offset subnet If the IP exceeds the maxium IP then the second return value is true

func PreviousSubnet

func PreviousSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool)

PreviousSubnet returns the subnet of the desired mask in the IP space just lower than the start of IPNet provided. If the IP space rolls over then the second return value is true

func SubmitFaiure

func SubmitFaiure(w http.ResponseWriter, statusCode int, message string)

Submit Failure Data To the client

func SubmitSuccess

func SubmitSuccess(w http.ResponseWriter, message string)

Submit Success Data To the client

func Subnet

func Subnet(base *net.IPNet, newBits int, num int) (*net.IPNet, error)

Subnet takes a parent CIDR range and creates a subnet within it with the given number of additional prefix bits and the given network number.

For example, 10.3.0.0/16, extended by 8 bits, with a network number of 5, becomes 10.3.5.0/24 .

func VerifyNoOverlap

func VerifyNoOverlap(subnets []*net.IPNet, CIDRBlock *net.IPNet) error

VerifyNoOverlap takes a list subnets and supernet (CIDRBlock) and verifies none of the subnets overlap and all subnets are in the supernet it returns an error if any of those conditions are not satisfied

Types

type ApiAction

type ApiAction interface {
	// Execute API command with API given arguments
	Run(Args ...interface{}) error
}

Interface that describes the callback action of an API call

type ContextKey

type ContextKey string

Context Key Type

func (ContextKey) String

func (c ContextKey) String() string

type MimeType

type MimeType string

Mime Type

type RestMethod

type RestMethod string

Rest Web Method Type

type RestProtocol

type RestProtocol string

Rest Protocol Type

Jump to

Keyboard shortcuts

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