utils

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

包utils提供了一些内部使用的工具函数。

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTrimChars 是默认被 Trim* 函数去除的字符集合。
	DefaultTrimChars = string([]byte{
		'\t',
		'\v',
		'\n',
		'\r',
		'\f',
		' ',
		0x00,
		0x85,
		0xA0,
	})
)

Functions

func EqualFoldWithoutChars

func EqualFoldWithoutChars(s1, s2 string) bool

EqualFoldWithoutChars 检查字符串 `s1` 和 `s2` 是否不区分大小写相等, 同时在有/无 '-'/'_'/'.'/' ' 这些字符的情况下进行比较。

func FormatCmdKey

func FormatCmdKey(s string) string

FormatCmdKey 将字符串`s`格式化为统一格式的命令键。

func FormatEnvKey

func FormatEnvKey(s string) string

FormatEnvKey 将字符串`s`格式化为统一格式的环境变量键。

func IsArray

func IsArray(value interface{}) bool

IsArray 检查给定的值是否为数组或切片。 注意,该功能内部使用了 reflect 实现。

func IsDebugEnabled

func IsDebugEnabled() bool

IsDebugEnabled 检查并返回是否启用了调试模式。 当命令行参数 "gf.debug" 或环境变量 "GF_DEBUG" 被设置时,调试模式将被启用。

func IsEmpty

func IsEmpty(value interface{}) bool

IsEmpty 检查 `value` 是否为空。

func IsFloat

func IsFloat(value interface{}) bool

IsFloat 检查 `value` 是否为浮点类型。

func IsInt

func IsInt(value interface{}) bool

IsInt 检查 `value` 是否为 int 类型。

func IsLetter

func IsLetter(b byte) bool

IsLetter 检查给定的字节 b 是否为字母。

func IsLetterLower

func IsLetterLower(b byte) bool

IsLetterLower 检查给定的字节 b 是否为小写字母。

func IsLetterUpper

func IsLetterUpper(b byte) bool

IsLetterUpper 检查给定的字节 b 是否为大写字母。

func IsMap

func IsMap(value interface{}) bool

IsMap 检查 `value` 是否为 map 类型。

func IsNumeric

func IsNumeric(s string) bool

IsNumeric 检查给定的字符串 s 是否为数值类型。 注意,小数形式的字符串如 "123.456" 也被视为数值类型。

func IsSlice

func IsSlice(value interface{}) bool

IsSlice 检查 `value` 是否为切片类型。

func IsStruct

func IsStruct(value interface{}) bool

IsStruct 检查 `value` 是否为结构体类型。

func IsUint

func IsUint(value interface{}) bool

IsUint 检查 `value` 是否为 uint 类型。

func ListToMapByKey

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

ListToMapByKey 将 `list` 转换为一个 map[string]interface{},其中键由 `key` 指定。 注意,项的值可能为 slice 类型。

func MapContainsPossibleKey

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

MapContainsPossibleKey 检查给定的 `key` 是否包含在给定的映射 `data` 中。 它在忽略大小写和符号的情况下检查键值。

注意,此函数可能性能较低。

func MapPossibleItemByKey

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

MapPossibleItemByKey尝试通过忽略大小写和符号的方式,为给定的键查找可能的键值对。

注意:此函数可能性能较低。

func NewReadCloser

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

NewReadCloser 创建并返回一个 RepeatReadCloser 对象。

func RemoveSymbols

func RemoveSymbols(s string) string

RemoveSymbols 从字符串中移除所有符号,仅保留数字和字母。

func ReplaceByMap

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

ReplaceByMap 函数返回 `origin` 的一个副本, 并使用一个无序的映射进行替换,且替换操作区分大小写。

func SetDebugEnabled

func SetDebugEnabled(enabled bool)

SetDebugEnabled 用于开启或关闭内部调试信息。

func SplitAndTrim

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

SplitAndTrim通过字符串`delimiter`将字符串`str`分割成一个数组, 然后对数组中的每个元素调用Trim方法。它会忽略经过Trim处理后为空的元素。

func StripSlashes

func StripSlashes(str string) string

StripSlashes 将通过 AddSlashes 方法添加了反斜杠的字符串进行去除引用操作。

func Trim

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

Trim 函数用于从字符串的开头和结尾去除空格(或其他字符)。 可选参数 `characterMask` 指定了需要额外去除的字符。

func UcFirst

func UcFirst(s string) string

UcFirst 返回一个字符串 s 的副本,其中首字母已转换为大写。

func X是否为Nil

func X是否为Nil(value interface{}) bool

IsNil 检查 `value` 是否为 nil,特别是针对 interface{} 类型的值。

Types

type ReadCloser

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

ReadCloser 实现了 io.ReadCloser 接口, 这个接口常用于多次读取请求正文内容。

注意,它不能被关闭。

func (*ReadCloser) Close

func (b *ReadCloser) Close() error

Close 实现了 io.ReadCloser 接口中的 Close 方法。

func (*ReadCloser) Read

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

Read 实现了 io.ReadCloser 接口。

Jump to

Keyboard shortcuts

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