util

package
v0.0.0-testrgm6 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: AGPL-3.0 Imports: 28 Imported by: 3,156

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWalkSkipDir = errors.New("skip this directory")

ErrWalkSkipDir is the Error returned when we want to skip descending into a directory

Functions

func ByteCountSI

func ByteCountSI(b int64) string

func Capitalize

func Capitalize(s string) string

func CleanRelativePath

func CleanRelativePath(path string) (string, error)

CleanRelativePath returns the shortest path name equivalent to path by purely lexical processing. It make sure the provided path is rooted and then uses filepath.Clean and filepath.Rel to make sure the path doesn't include any separators or elements that shouldn't be there like ., .., //.

func DecodeBasicAuthHeader

func DecodeBasicAuthHeader(header string) (string, string, error)

DecodeBasicAuthHeader decodes user and password from a basic auth header.

func DecodeQuotedPrintable

func DecodeQuotedPrintable(encodedValue string) string

decodeQuotedPrintable decodes quoted-printable UTF-8 string

func Decrypt

func Decrypt(payload []byte, secret string) ([]byte, error)

Decrypt decrypts a payload with a given secret. DEPRECATED. Do not use it. Use secrets.Service instead.

func EncodePassword

func EncodePassword(password string, salt string) (string, error)

EncodePassword encodes a password using PBKDF2.

func Encrypt

func Encrypt(payload []byte, secret string) ([]byte, error)

Encrypt encrypts a payload with a given secret. DEPRECATED. Do not use it. Use secrets.Service instead.

func GenerateShortUID

func GenerateShortUID() string

GenerateShortUID will generate a UUID that can also be a k8s name it is guaranteed to have a character as the first letter This UID will be a valid k8s name

func GetAgeString

func GetAgeString(t time.Time) string

GetAgeString returns a string representing certain time from years to minutes.

func GetBasicAuthHeader

func GetBasicAuthHeader(user string, password string) string

GetBasicAuthHeader returns a base64 encoded string from user and password.

func GetRandomString

func GetRandomString(n int, alphabets ...byte) (string, error)

GetRandomString generates a random alphanumeric string of the specified length, optionally using only specified characters

func IsEmail

func IsEmail(str string) bool

IsEmail checks if a string is a valid email address.

func IsShortUIDTooLong

func IsShortUIDTooLong(uid string) bool

IsShortUIDTooLong checks if short unique identifier is too long

func IsValidShortUID

func IsValidShortUID(uid string) bool

IsValidShortUID checks if short unique identifier contains valid characters NOTE: future Grafana UIDs will need conform to https://github.com/kubernetes/apimachinery/blob/master/pkg/util/validation/validation.go#L43

func JoinURLFragments

func JoinURLFragments(a, b string) string

JoinURLFragments joins two ApiURL fragments into only one ApiURL string.

func Md5Sum

func Md5Sum(reader io.Reader) (string, error)

Md5Sum calculates the md5sum of a stream

func Md5SumString

func Md5SumString(input string) (string, error)

Md5SumString calculates the md5sum of a string

func MinInt

func MinInt(x, y int) int

MinInt returns the smaller of x or y.

func Pointer

func Pointer[T any](v T) *T

func RandomHex

func RandomHex(n int) (string, error)

RandomHex returns a hex encoding of n random bytes.

func Reverse

func Reverse[T comparable](input []T) []T

Reverse returns a new slice with reversed order

func SplitEmails

func SplitEmails(emails string) []string

SplitEmails splits addresses with a few different ways

func SplitString

func SplitString(str string) []string

SplitString splits a string by commas or empty spaces.

func StringsFallback2

func StringsFallback2(val1 string, val2 string) string

StringsFallback2 returns the first of two not empty strings.

func StringsFallback3

func StringsFallback3(val1 string, val2 string, val3 string) string

StringsFallback3 returns the first of three not empty strings.

func TlsCipherIdsToString

func TlsCipherIdsToString(ids []uint16) string

tlsNameToVersion converts a tls version to a string

func TlsCiphersToIDs

func TlsCiphersToIDs(names []string) ([]uint16, error)

Cipher strings https://go.dev/src/crypto/tls/cipher_suites.go Ex: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" or "TLS_RSA_WITH_AES_128_CBC_SHA"

func TlsNameToVersion

func TlsNameToVersion(name string) (uint16, error)

tlsNameToVersion converts a string to a tls version

func ToCamelCase

func ToCamelCase(str string) string

ToCamelCase changes kebab case, snake case or mixed strings to camel case. See unit test for examples.

func Walk

func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walkFn WalkFunc) error

Walk walks a path, optionally following symbolic links, and for each path, it calls the walkFn passed.

It is similar to filepath.Walk, except that it supports symbolic links and can detect infinite loops while following sym links. It solves the issue where your WalkFunc needs a path relative to the symbolic link (resolving links within walkfunc loses the path to the symbolic link for each traversal).

Types

type CancelCauseFunc

type CancelCauseFunc func(error)

func WithCancelCause

func WithCancelCause(parent context.Context) (context.Context, CancelCauseFunc)

WithCancelCause creates a cancellable context that can be cancelled with a custom reason

type DynMap

type DynMap map[string]interface{}

DynMap defines a dynamic map interface.

type NetworkAddress

type NetworkAddress struct {
	Host string
	Port string
}

func SplitHostPortDefault

func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddress, error)

SplitHostPortDefault splits ip address/hostname string by host and port. Defaults used if no match found

type URLQueryReader

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

URLQueryReader is a ApiURL query type.

func NewURLQueryReader

func NewURLQueryReader(urlInfo *url.URL) (*URLQueryReader, error)

NewURLQueryReader parses a raw query and returns it as a URLQueryReader type.

func (*URLQueryReader) Get

func (r *URLQueryReader) Get(name string, def string) string

Get parse parameters from an ApiURL. If the parameter does not exist, it returns the default value.

type WalkFunc

type WalkFunc func(resolvedPath string, info os.FileInfo, err error) error

WalkFunc is a callback function called for each path as a directory is walked If resolvedPath != "", then we are following symbolic links.

Directories

Path Synopsis
Package errutil provides utilities for working with errors in Grafana.
Package errutil provides utilities for working with errors in Grafana.
xorm module

Jump to

Keyboard shortcuts

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