utils

package
v2.7.5 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package utils provides some utility functions for internal usage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTrimChars are the characters which are stripped by Trim* functions in default.
	DefaultTrimChars = string([]byte{
		'\t',
		'\v',
		'\n',
		'\r',
		'\f',
		' ',
		0x00,
		0x85,
		0xA0,
	})
)

Functions

func CanCallIsNil added in v2.7.2

func CanCallIsNil(v interface{}) bool

CanCallIsNil Can reflect.Value call reflect.Value.IsNil. It can avoid reflect.Value.IsNil panics.

func EqualFoldWithoutChars

func EqualFoldWithoutChars(s1, s2 string) bool

EqualFoldWithoutChars checks string `s1` and `s2` equal case-insensitively, with/without chars '-'/'_'/'.'/' '.

func FormatCmdKey

func FormatCmdKey(s string) string

FormatCmdKey formats string `s` as command key using uniformed format.

func FormatEnvKey

func FormatEnvKey(s string) string

FormatEnvKey formats string `s` as environment key using uniformed format.

func IsArray

func IsArray(value interface{}) bool

IsArray checks whether given value is array/slice. Note that it uses reflect internally implementing this feature.

func IsDebugEnabled

func IsDebugEnabled() bool

IsDebugEnabled checks and returns whether debug mode is enabled. The debug mode is enabled when command argument "gf.debug" or environment "GF_DEBUG" is passed.

func IsEmpty

func IsEmpty(value interface{}) bool

IsEmpty checks whether `value` is empty.

func IsFloat

func IsFloat(value interface{}) bool

IsFloat checks whether `value` is type of float.

func IsInt

func IsInt(value interface{}) bool

IsInt checks whether `value` is type of int.

func IsLetter

func IsLetter(b byte) bool

IsLetter checks whether the given byte b is a letter.

func IsLetterLower

func IsLetterLower(b byte) bool

IsLetterLower checks whether the given byte b is in lower case.

func IsLetterUpper

func IsLetterUpper(b byte) bool

IsLetterUpper checks whether the given byte b is in upper case.

func IsMap

func IsMap(value interface{}) bool

IsMap checks whether `value` is type of map.

func IsNil

func IsNil(value interface{}) bool

IsNil checks whether `value` is nil, especially for interface{} type value.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks whether the given string s is numeric. Note that float string like "123.456" is also numeric.

func IsSlice

func IsSlice(value interface{}) bool

IsSlice checks whether `value` is type of slice.

func IsStruct

func IsStruct(value interface{}) bool

IsStruct checks whether `value` is type of struct.

func IsUint

func IsUint(value interface{}) bool

IsUint checks whether `value` is type of uint.

func ListToMapByKey

func ListToMapByKey(list []map[string]interface{}, key string) map[string]interface{}

ListToMapByKey converts `list` to a map[string]interface{} of which key is specified by `key`. Note that the item value may be type of slice.

func MapContainsPossibleKey

func MapContainsPossibleKey(data map[string]interface{}, key string) bool

MapContainsPossibleKey checks if the given `key` is contained in given map `data`. It checks the key ignoring cases and symbols.

Note that this function might be of low performance.

func MapPossibleItemByKey

func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{})

MapPossibleItemByKey tries to find the possible key-value pair for given key ignoring cases and symbols.

Note that this function might be of low performance.

func NewReadCloser

func NewReadCloser(content []byte, repeatable bool) io.ReadCloser

NewReadCloser creates and returns a RepeatReadCloser object.

func RemoveSymbols

func RemoveSymbols(s string) string

RemoveSymbols removes all symbols from string and lefts only numbers and letters.

func ReplaceByMap

func ReplaceByMap(origin string, replaces map[string]string) string

ReplaceByMap returns a copy of `origin`, which is replaced by a map in unordered way, case-sensitively.

func SetDebugEnabled

func SetDebugEnabled(enabled bool)

SetDebugEnabled enables/disables the internal debug info.

func SplitAndTrim

func SplitAndTrim(str, delimiter string, characterMask ...string) []string

SplitAndTrim splits string `str` by a string `delimiter` to an array, and calls Trim to every element of this array. It ignores the elements which are empty after Trim.

func StripSlashes

func StripSlashes(str string) string

StripSlashes un-quotes a quoted string by AddSlashes.

func Trim

func Trim(str string, characterMask ...string) string

Trim strips whitespace (or other characters) from the beginning and end of a string. The optional parameter `characterMask` specifies the additional stripped characters.

func UcFirst

func UcFirst(s string) string

UcFirst returns a copy of the string s with the first letter mapped to its upper case.

Types

type ReadCloser

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

ReadCloser implements the io.ReadCloser interface which is used for reading request body content multiple times.

Note that it cannot be closed.

func (*ReadCloser) Close

func (b *ReadCloser) Close() error

Close implements the io.ReadCloser interface.

func (*ReadCloser) Read

func (b *ReadCloser) Read(p []byte) (n int, err error)

Read implements the io.ReadCloser interface.

Jump to

Keyboard shortcuts

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