shared

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFullFilePath

func BuildFullFilePath(filename string) string

func CloseQuietly

func CloseQuietly(c io.Closer) func()

CloseQuietly - Returns a function that closes a `Closer` object without returning any error

func CreateTempFileFromStringData

func CreateTempFileFromStringData(namePrefix string, contents string) (string, error)

func DiffAsJson

func DiffAsJson(a interface{}, b interface{}, aName string, bName string) string

func GetProjectRootDir

func GetProjectRootDir() string

GetProjectRootDir returns the root directory of the project. The root directory of the project is the directory that contains the go.mod file which contains the "github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager" module name.

func HandleError

func HandleError(r *http.Request, w http.ResponseWriter, err *errors.ServiceError)

HandleError handles a service error by returning an appropriate HTTP response with error reason

func IsNil

func IsNil[T any](x T) bool

IsNil - returns `true` if the value is nil

func IsNotNil

func IsNotNil[T any](x T) bool

IsNotNil - Returns `true` if the passed in value is not nil

func LoadOpenAPISpecFromYAML

func LoadOpenAPISpecFromYAML(openapiYAMLBytes []byte) (data []byte, err error)

func ReadFile

func ReadFile(file string) (string, error)

func ReadFileValueBool

func ReadFileValueBool(file string, val *bool) error

Read the contents of file into boolean value

func ReadFileValueInt

func ReadFileValueInt(file string, val *int) error

Read the contents of file into integer value

func ReadFileValueString

func ReadFileValueString(file string, val *string) error

Read the contents of file into string value

func ReadJSONFile

func ReadJSONFile(filename string, out interface{}) error

ReadJSONFile reads a JSON file located in `filename` path and leaves the result in the `out` argument. If the file exists but it is empty or only contain blanks the method succeeds leaving the `out` argument unmodified

func ReadYamlFile

func ReadYamlFile(filename string, out interface{}) (err error)

func RoundDown

func RoundDown(number int, multiple int) int

RoundDown rounds up number to the nearest multiple. number and multiple are expected to be positive

func RoundUp

func RoundUp(number int, multiple int) int

RoundUp rounds up number to the nearest multiple. number and multiple are expected to be positive

func SafeInt64

func SafeInt64(ptr *int64) int64

SafeInt64 - Converts an Int64 pointer to an Int64. If the pointer is `nil`, returns 0

func SafeString

func SafeString(ptr *string) string

SafeString - Converts a string pointer to a string. If the pointer is `nil`, returns the empty string

func StringEmpty

func StringEmpty[T string | *string](x T, trim ...bool) bool

StringEmpty - returns `true` if the value is nil or is the empty string. Works with both `string` and `*string` objects. If `trim` is specified and is `true` trims the string (only first value is considered).

func StringEqualsIgnoreCase

func StringEqualsIgnoreCase[T string | *string](s1 T, s2 T) bool

StringEqualsIgnoreCase - Compare 2 strings ignoring the case. Works with both string and *string values. If s1 == s2 == nil, returns `true`

func StringHasPrefixIgnoreCase

func StringHasPrefixIgnoreCase[T string | *string](s T, prefix T) bool

StringHasPrefixIgnoreCase - returns true if s starts with T, ignoring the case Works with both string and *string values.

func StringHasSuffixIgnoreCase

func StringHasSuffixIgnoreCase[T string | *string](s T, suffix T) bool

StringHasSuffixIgnoreCase - returns true if s ends with T, ignoring the case Works with both string and *string values.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, code int, payload interface{})

WriteJSONResponse writes a json HTTP response of the given HTTP status code and response payload

func WriteStreamJSONResponseWithContentType

func WriteStreamJSONResponseWithContentType(w http.ResponseWriter, code int, payload interface{}, contentType string)

WriteJSONResponse writes a HTTP response of the given HTTP status code and response payload with a given content type

Types

This section is empty.

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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