utils

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeFullPath

func ComputeFullPath(url string, r *http.Request) string

ComputeFullPath will add the current canonical hostname to a URL, if it doesn't already contain the canonical hostname (i.e. it is only a path)

func EnvOrDefault

func EnvOrDefault(name, def string) string

EnvOrDefault returns the value of the environment variable identified by name parameter, or the value of the def parameter if the environment variable is missing.

Note: It will return an empty string if the environment variable is set to an empty string.

func EnvOrDefaultBool

func EnvOrDefaultBool(name string, def bool) bool

EnvOrDefaultBool returns the value of the environment variable identified by name parameter cast to a boolean, or the value of the def parameter if the environment variable is missing or empty.

Note: It will return the value of def if the environment variable is set to an empty string.

func EnvOrDefaultInt32

func EnvOrDefaultInt32(name string, def int32) int32

EnvOrDefaultInt32 returns the value of the environment variable identified by name parameter cast to a 32bit decimal integer, or the value of the def parameter if the environment variable is missing or empty.

Note: It will return the value of def if the environment variable is set to an empty string.

func EnvOrDefaultInt64

func EnvOrDefaultInt64(name string, def int64) int64

EnvOrDefaultInt64 returns the value of the environment variable identified by name parameter cast to a 64bit decimal integer, or the value of the def parameter if the environment variable is missing or empty.

Note: It will return the value of def if the environment variable is set to an empty string.

func EnvOrDefaultStringSlice

func EnvOrDefaultStringSlice(name, separator string, def []string) []string

EnvOrDefaultStringSlice returns the value of the environment variable identified by name parameter split by the value of the separator parameter as a slice of strings, or the value of the def parameter if the environment variable is missing.

Note: It will return an empty slice if the environment variable is set to an empty string.

func GetFunctionListeningPort

func GetFunctionListeningPort() (port, cloud string, err error)

GetFunctionListeningPort will return the port on which the function is listening to and the cloud it believes the function is running in, or an error. Currently only supports Azure Functions.

func GetHttpRequestBaseUrl

func GetHttpRequestBaseUrl(r *http.Request) string

GetHttpRequestBaseUrl returns a canonical hostname for the current request in the form of <scheme>://<host or ip>:<port>

func GetHttpRequestScheme

func GetHttpRequestScheme(r *http.Request) string

GetHttpRequestScheme determines the protocol scheme used in the request call. Returns either "http" or "https", always lowercase

func InitTracerJaeger

func InitTracerJaeger(jaegerEndpoint, serviceNameKey, serviceInstanceIDKey, tenant string) (*trace.TracerProvider, error)

func InitTracerStdout

func InitTracerStdout() (*trace.TracerProvider, error)

func RandomString

func RandomString(n int) string

Types

type HttpError

type HttpError struct {
	Code    int
	Err     error
	Message string
}

HttpError defines the generic structure of an HTTP error response.

func (*HttpError) Error

func (err *HttpError) Error() string

Error will return the string representation of the HttpError.Message and Err, omitting the former if it is not set.

func (*HttpError) ErrorAndStack

func (err *HttpError) ErrorAndStack() (string, string)

ErrorAndStack will return both the output of Error and StackTrace in one call

func (*HttpError) StackTrace

func (err *HttpError) StackTrace() string

StackTrace will return a string representation of Err's stack trace

Jump to

Keyboard shortcuts

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