Documentation ¶
Overview ¶
Package util provides a multitude of support functions to help make development easier. Use of these functions should be preferred, as it allows for easier maintenance.
Index ¶
- Constants
- Variables
- func CombineConfig(entries []string) string
- func ConvertToStringMap(data map[string]interface{}) map[string]string
- func CopyMap(m map[string]interface{}) (map[string]interface{}, error)
- func Distances(pnts []Point) [][]float64
- func Distribute(nodes []string, dist []int) ([][]string, error)
- func ExtractJwt(r *http.Request) (string, error)
- func ExtractStringMap(in map[string]interface{}, key string) (map[string]interface{}, bool)
- func FormatError(res string, err error) error
- func GenerateDependentMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateNoDuplicateMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateUniformRandMeshNetwork(nodes int, conns int) ([][]int, error)
- func GenerateworstCaseNetwork(nodes int) [][]int
- func GetGateway(server int, network int) string
- func GetGateways(server int, networks int) []string
- func GetInfoFromIP(ipStr string) (int, int, int)
- func GetJSONInt64(data map[string]interface{}, field string, out *int64) error
- func GetJSONString(data map[string]interface{}, field string, out *string) error
- func GetKidFromJwt(jwt string) (string, error)
- func GetNetworkAddress(server int, network int) string
- func GetNodeIP(server int, network int, index int) (string, error)
- func GetPath(path string) string
- func GetServiceIps(services []Service) (map[string]string, error)
- func GetServiceNetwork() (string, string, error)
- func GetSubnet() int
- func GetUUIDString() (string, error)
- func GetUniqueStrings(in []string) []string
- func GetWholeNetworkIP(server int) string
- func HTTPRequest(method string, url string, bodyData string) ([]byte, error)
- func InetNtoa(ip uint32) string
- func JwtHTTPRequest(method string, url string, jwt string, bodyData string) (string, error)
- func LogError(err error) error
- func Lsr(_dir string) ([]string, error)
- func MergeStringMaps(m1 map[string]interface{}, m2 map[string]interface{}) map[string]interface{}
- func Rm(directories ...string) error
- func ValidNormalCharacter(chr rune) bool
- func ValidateASCII(str string) error
- func ValidateCommandLine(str string) error
- func ValidateFilePath(path string) error
- func ValidateNormalASCII(str string) error
- type Command
- type Config
- type EndPoint
- type KeyPair
- type Point
- type Resources
- type Service
Constants ¶
const ReservedIps uint32 = 3
ReservedIps indicates the number of ip addresses reserved in a cluster's subnet
Variables ¶
var NodesPerCluster uint32
NodesPerCluster represents the maximum number of nodes allowed in a cluster
Functions ¶
func CombineConfig ¶
CombineConfig combines an Array with \n as the delimiter. Useful for generating configuration files. DEPRECATED
func ConvertToStringMap ¶
ConvertToStringMap converts a map of string to interface to a map of string to json
func Distribute ¶
Distribute generates a roughly uniform random distribution for connections among nodes.
func ExtractJwt ¶
ExtractJwt will attempt to extract and return the jwt from the auth header
func ExtractStringMap ¶ added in v1.6.5
ExtractStringMap extracts a map[string]interface from a map[string]interface
func FormatError ¶
FormatError produced a standard error for execution.
func GenerateDependentMeshNetwork ¶ added in v1.7.2
GenerateDependentMeshNetwork generates a random mesh network that ensures the if built in order, each node will be given a list of peers which is already up and running. Note: This means that the first node will have an empty list
func GenerateNoDuplicateMeshNetwork ¶ added in v1.7.2
GenerateNoDuplicateMeshNetwork generates a random mesh network that ensures that peering there is always a path between all the nodes, without any duplication. That is, if 1 contains 3, 3 won't contain 1 by elimination
func GenerateUniformRandMeshNetwork ¶
GenerateUniformRandMeshNetwork generates a random mesh network that ensures that there is always a path between all the nodes
func GenerateworstCaseNetwork ¶
GenerateworstCaseNetwork generates a random path through all nodes
func GetGateway ¶
GetGateway calculates the gateway IP address for a node, base on the current IP scheme
func GetGateways ¶
GetGateways calculates the gateway IP addresses for all of the nodes on a server.
func GetInfoFromIP ¶
GetInfoFromIP returns the server number and the node number calculated from the given IPv4 address based on the current IP scheme. (server,network,index)
func GetJSONInt64 ¶
GetJSONInt64 checks and extracts a int64 from data[field]. Will return an error if data[field] does not exist or is of the wrong type.
func GetJSONString ¶
GetJSONString checks and extracts a string from data[field]. Will return an error if data[field] does not exist or is of the wrong type.
func GetKidFromJwt ¶
GetKidFromJwt will attempt to extract the kid from the given jwt
func GetNetworkAddress ¶
GetNetworkAddress gets the network address of the cluster the given node belongs to.
func GetServiceIps ¶
GetServiceIps creates a map of the service names to their ip addresses. Useful for determining the ip address of a service.
func GetServiceNetwork ¶
GetServiceNetwork gets the network address in CIDR of the service network
func GetUniqueStrings ¶ added in v1.6.5
GetUniqueStrings returns the given slice of strings without the duplicates
func GetWholeNetworkIP ¶ added in v1.6.5
GetWholeNetworkIP gets the network ip of the whole network for a server.
func HTTPRequest ¶ added in v1.6.5
HTTPRequest Sends a HTTP request and returns the body. Gives an error if the http request failed or returned a non success code.
func InetNtoa ¶
InetNtoa converts the IP address, given in network byte order, to a string in IPv4 dotted-decimal notation.
func JwtHTTPRequest ¶ added in v1.6.5
JwtHTTPRequest is similar to HttpRequest, but it have the content-type set as application/json and it will put the given jwt in the auth header
func LogError ¶ added in v1.7.1
LogError acts like log.Println() but takes in an error and returns that error. Used to help reduce code clutter from all the log.Println(err) in the code. Has no effect is err == nil
func MergeStringMaps ¶
MergeStringMaps merges two maps of string to interface together and returns it If there are conflicting keys, the value in m2 will be chosen.
func ValidNormalCharacter ¶
ValidNormalCharacter checks to make sure a character is within a safe range to naively prevent most bash injects (Not for security, only for debugging)
func ValidateASCII ¶ added in v1.6.5
ValidateASCII checks if the given string only contains standard ASCII characters, which can fit in a signed char
func ValidateCommandLine ¶
ValidateCommandLine naively checks for ppntential accidental bash injections. Like ValidNormalCharacter, is not too be considered useful for security, only for picking up on potential bugs.
func ValidateFilePath ¶
ValidateFilePath check to make sure there is nothing malicous in the file path
func ValidateNormalASCII ¶ added in v1.6.5
ValidateNormalASCII is similar to ValidateAscii, except that it excludes control characters from the set of acceptable characters. Any character 127 > c > 31 is considered valid
Types ¶
type Config ¶
type Config struct { SSHUser string `json:"ssh-user"` SSHKey string `json:"ssh-key"` ServerBits uint32 `json:"server-bits"` ClusterBits uint32 `json:"cluster-bits"` NodeBits uint32 `json:"node-bits"` IPPrefix uint32 `json:"ip-prefix"` Listen string `json:"listen"` Verbosity string `json:"verbosity"` ThreadLimit int64 `json:"thread-limit"` DockerOutputFile string `json:"docker-output-file"` Influx string `json:"influx"` InfluxUser string `json:"influx-user"` InfluxPassword string `json:"influx-password"` ServiceNetwork string `json:"service-network"` ServiceNetworkName string `json:"service-network-name"` NodePrefix string `json:"node-prefix"` NodeNetworkPrefix string `json:"node-network-prefix"` ServicePrefix string `json:"service-prefix"` NodesPublicKey string `json:"nodes-public-key"` NodesPrivateKey string `json:"nodes-private-key"` HandleNodeSSHKeys bool `json:"handle-node-ssh-keys"` MaxNodes int `json:"max-nodes"` MaxNodeMemory string `json:"max-node-memory"` MaxNodeCPU float64 `json:"max-node-cpu"` BridgePrefix string `json:"bridge-prefix"` APIEndpoint string `json:"api-endpoint"` NibblerEndPoint string `json:"nibbler-end-point"` }
Config groups all of the global configuration parameters into a single struct
func GetConfig ¶
func GetConfig() *Config
GetConfig gets a pointer to the global config object. Do not modify c object
func (*Config) AutoFillMissing ¶
func (c *Config) AutoFillMissing()
AutoFillMissing fills in the missing essential values with the defaults.
func (*Config) LoadFromEnv ¶
func (c *Config) LoadFromEnv()
LoadFromEnv loads the configuration from the Environment
type EndPoint ¶
type EndPoint struct { URL string `json:"url"` User string `json:"user"` Pass string `json:"pass"` }
EndPoint represents an endpoint with basic auth
type Point ¶
type Point struct { //X represents the position on the x axis X int `json:"x"` //Y represents the position on the y axis Y int `json:"y"` }
Point represents a basic 2D coordinate point
type Resources ¶
type Resources struct { // Cpus should be a floating point value represented as a string, and // is equivalent to the percentage of a single cores time which can be used // by a node. Can be more than 1.0, meaning the node can use multiple cores at // a time. Cpus string `json:"cpus"` // Memory supports values up to Terrabytes (tb). If the unit is omitted, then it // is assumed to be bytes. This is not case sensitive. Memory string `json:"memory"` // Volumes to be used by each node. Volumes []string `json:"volumes"` // Ports to be opened for each node, each item associated with one node. Ports []string `json:"ports"` }
Resources represents the maximum amount of resources that a node can use.
func (Resources) NoCPULimits ¶ added in v1.6.5
NoCPULimits checks if the resources object doesn't specify any cpu limits
func (Resources) NoMemoryLimits ¶
NoMemoryLimits checks if the resources object doesn't specify any memory limits
func (Resources) Validate ¶
Validate ensures that the given resource object is valid, and allowable.
func (Resources) ValidateAndSetDefaults ¶
ValidateAndSetDefaults calls Validate, and if it is valid, fills any missing information. Helps to ensure that the Maximum limits are enforced.