common

package
v0.0.0-...-7b2e207 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: AGPL-3.0 Imports: 17 Imported by: 18

Documentation

Overview

Package glogger defines glog-based logging for grpc.

Index

Constants

This section is empty.

Variables

View Source
var SupportedResourceSets = map[string]map[string]int{
	"s1": {
		"cpuShare": 100,
		"memory":   256,
		"disk":     4000,
	},
	"s2": {
		"cpuShare": 100,
		"memory":   512,
		"disk":     4000,
	},
	"m1": {
		"cpuShare": 100,
		"memory":   1024,
		"disk":     4000,
	},
	"m2": {
		"cpuShare": 200,
		"memory":   2048,
		"disk":     4000,
	},
}

SupportedResourceSets defines the support sets of resources that can be allocated to a task

Functions

func CapitalizeString

func CapitalizeString(str string) string

CapitalizeString capitalizes the first character of all sentences in a given string.

func CompareErr

func CompareErr(errA, errB error) int

CompareErr compares two error string values. Returns 0 if equal. Removes GRPC prefixes if available.

func GetAuthToken

func GetAuthToken(ctx context.Context, scheme string) (string, error)

GetAuthToken returns authorization code of a specific bearer from a context

func GetRPCErrDesc

func GetRPCErrDesc(err error) string

GetRPCErrDesc takes a grpc generated error and returns the description. If error is not grpc generated, it returns err.Error().

func GetResourceSet

func GetResourceSet(memory, cpuShare int) map[string]map[string]int

GetResourceSet returns the full resource where the resource attributes match the one passed

func GetShortID

func GetShortID(id string) string

GetShortID gets the short version of an id.

func HasEnv

func HasEnv(envs ...string) []string

HasEnv checks whether a slice of environment variable have been set. It returns the variables that haven't been set

func IsUniqueConstraintError

func IsUniqueConstraintError(err error, column string) bool

IsUniqueConstraintError checks whether an error is a postgres contraint error affecting a column.

func IsValidACLTarget

func IsValidACLTarget(target string) error

IsValidACLTarget checks whether an ACL target format is valid

func IsValidCocoonID

func IsValidCocoonID(name string) bool

IsValidCocoonID checks whether a name is a accepted cocoon name

func IsValidResName

func IsValidResName(name string) bool

IsValidResName checks whether a name is a accepted resource name format.

func JSONCoerceErr

func JSONCoerceErr(objName string, err error) error

JSONCoerceErr returns an error about an error converting json data to an object

func MBToByte

func MBToByte(mb int64) int64

MBToByte returns the amount of bytes in a MB.

func MergeMapSlice

func MergeMapSlice(s []map[string]interface{}) map[string]interface{}

MergeMapSlice merges a slice of maps into a single map with the each successive maps overwriting previously available keys

func NewLock

func NewLock(key string) (types.Lock, error)

NewLock creates a lock. If `DEV_MEM_LOCK` is set, a memory lock will be returned

func NewLockWithTTL

func NewLockWithTTL(key string, ttl time.Duration) (types.Lock, error)

NewLockWithTTL creates a lock with a custom ttl. If `DEV_MEM_LOCK` is set, a memory lock will be returned

func OnTerminate

func OnTerminate(f func(s os.Signal))

OnTerminate calls a function when a terminate or interrupt signal is received.

func ReRunOnError

func ReRunOnError(f func() error, times int, delay time.Duration) error

ReRunOnError runs a function multiple times till it returns a non-error (nil) value. It accepts a limit on how many times to attempt a re-run and a delay duration. If delay is nil, there is no delay. It returns the last error of the last re-run attempt if the function did not succeed.

func RemoveASCIIColors

func RemoveASCIIColors(s []byte) []byte

RemoveASCIIColors takes a byte slice and remove ASCII colors

func ResolveFirewall

func ResolveFirewall(rules types.Firewall) (types.Firewall, error)

ResolveFirewall performs a reverse lookup of non-IP destination of every rule. For each resolved rule, a new cloned rule is added with the looked up IP used as the destination.

func ReturnFirstIfDiffACLMap

func ReturnFirstIfDiffACLMap(a, b types.ACLMap) types.ACLMap

ReturnFirstIfDiffACLMap returns the first param (a) if it is different from the (b), otherwise b is returned

func ReturnFirstIfDiffEnv

func ReturnFirstIfDiffEnv(a, b types.Env) types.Env

ReturnFirstIfDiffEnv returns the first param (a) if it is different from the (b), otherwise b is returned

func ReturnFirstIfDiffInt

func ReturnFirstIfDiffInt(a, b int) int

ReturnFirstIfDiffInt returns the first param (a) if it is different from the (b) and not zero, otherwise b is returned

func ReturnFirstIfDiffString

func ReturnFirstIfDiffString(a, b string, secondIfEmpty bool) string

ReturnFirstIfDiffString returns the first param (a) if it is different from the (b), otherwise b is returned

func Round

func Round(val float64) int

Round rounds float values to the nearest integer

func SimpleGRPCError

func SimpleGRPCError(serviceName string, err error) error

SimpleGRPCError returns simplified, user-friendly grpc errors

func ToRPCError

func ToRPCError(code int, err error) error

ToRPCError creates an RPC error message

Types

type GLogger

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

GLogger defines glog-based logging for grpc. This is a modification of glogger (https://github.com/grpc/grpc-go/blob/master/grpclog/glogger/glogger.go) that includes a new Disable function to disable logging.

func (*GLogger) Disable

func (g *GLogger) Disable(v bool, includeFatal bool)

Disable prevents the logger from calling glog in non-fatal log methods. If includeFatal is set to true, fatal logs will be disabled.

func (*GLogger) Fatal

func (g *GLogger) Fatal(args ...interface{})

func (*GLogger) Fatalf

func (g *GLogger) Fatalf(format string, args ...interface{})

func (*GLogger) Fatalln

func (g *GLogger) Fatalln(args ...interface{})

func (*GLogger) Print

func (g *GLogger) Print(args ...interface{})

func (*GLogger) Printf

func (g *GLogger) Printf(format string, args ...interface{})

func (*GLogger) Println

func (g *GLogger) Println(args ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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