tool

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tool 常用的python标准库方法实现

Index

Constants

This section is empty.

Variables

View Source
var (
	MarshalJSON       = json.Marshal
	UnmarshalJSON     = json.Unmarshal
	MarshalJSONIndent = json.MarshalIndent
	NewJSONDecoder    = json.NewDecoder
	NewJSONEncoder    = json.NewEncoder
	// JSONFast 更快的配置,浮点数仅能保留6位小数, 且不能序列化HTML
	JSONFast          = jsoniter.ConfigFastest
	FastMarshalJSON   = JSONFast.Marshal
	FastUnmarshalJSON = JSONFast.Unmarshal
	// JSON 默认配置
	JSON      = JSONFast
	Marshal   = JSON.Marshal
	Unmarshal = JSON.Unmarshal
)
View Source
var (
	F           = CombineStrings
	StringsJoin = CombineStrings
)

Functions

func All

func All(args ...bool) bool

All 参数全部为true时为true

func Any

func Any(args ...bool) bool

Any 任意一个参数为true时为true

func B2S added in v0.1.1

func B2S(b []byte) string

B2S 将[]byte转换为字符串,(就地修改)零内存分配

func Base64Decode

func Base64Decode(data string) ([]byte, error)

Base64Decode base64解码

@param	data	string	base64字符串

func Base64Encode

func Base64Encode(data []byte) string

Base64Encode base64编码

@param	data	[]byte	字节流
@return	string base64字符串

func CombineStrings

func CombineStrings(elems ...string) string

CombineStrings 合并字符串, 实现等同于strings.Join(),只是少了判断分隔符

func Has

func Has[T comparable](s []T, x T) bool

Has 查找序列s内是否存在元素x

@param	s	[]T	查找序列
@param	x	T	特定元素
@return	bool true if s contains x, false otherwise

func HexBeautify

func HexBeautify(src []byte) string

HexBeautify 格式化显示十六进制

func In

func In[T comparable](s []T, x T) bool

In 查找序列s内是否存在元素x

@param	s	[]T	查找序列
@param	x	T	特定元素
@return	bool true if s contains x, false otherwise

func Index

func Index[T comparable](s []T, x T) int

Index 获取指定元素在列表中的下标,若不存在则返回-1

func IsEqual

func IsEqual[T comparable](a, b []T) bool

IsEqual 判断2个切片是否相等

@return	true if is equal

func MapToString

func MapToString(object map[string]any) string

MapToString 将字典转换成字符串显示

func Max

func Max[T types.Ordered](p ...T) T

Max 计算列表内部的最大元素, 需确保目标列表不为空

func Min

func Min[T types.Ordered](p ...T) T

Min 计算列表内部的最小元素, 需确保目标列表不为空

func Repr

func Repr(object any, excludeName ...bool) (message string)

Repr 格式化显示对象 将任意对象输出为字符串格式,内部对struct,map,array,string,error实现了string的格式化转换

number -> number
bool -> "true" or "false"
array -> "0d 56 f6";
map -> json;
struct -> StructName({json});
error -> error.Error();

@param	object		any		需要格式化显示的对象
@param	excludeName	bool	不显示对象名称,	针对struct有效
@return	string ObjectName(...)

func Reversed added in v0.1.1

func Reversed[T any](s *[]T)

Reversed 数组倒序, 就地修改

@param	s	*[]T	需要倒序的序列

func S2B added in v0.1.1

func S2B(s string) (b []byte)

S2B 将字符串转换为[]byte,(就地修改)零内存分配

func WordCapitalize

func WordCapitalize(word string) string

WordCapitalize 单词首字母大写

@param	word	string	单词
@return	string 首字母大写的单词

Types

This section is empty.

Jump to

Keyboard shortcuts

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