restutils

package
v0.0.0-...-e2a80a6 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AscSorted

func AscSorted[T constraints.Ordered](s []T) []T

AscSorted 返回升序排列的新切片。

func BytesFromURL

func BytesFromURL(ctx context.Context, rawUrl string) ([]byte, error)

BytesFromURL 从url获得数据。 支持的scheme:file://、http://、https://、data:。 url示例:file:///etc/fstab、data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==。

func CoarseTimestamp

func CoarseTimestamp() float64

CoarseTimestamp 当前时间戳。单位秒。精确到0.1秒。

func CompareHumanizeString

func CompareHumanizeString(a, b string) int

CompareHumanizeString 比较两个字符串,结果接近可视结果。

func DescSorted

func DescSorted[T constraints.Ordered](s []T) []T

DescSorted 返回降序排列的新切片。

func HitIndexes

func HitIndexes[T any](collection []T, missIndexes []int) []int

HitIndexes 根据未命中的索引,得到命中的索引

func IntSliceContains

func IntSliceContains(ints []int, n int) bool

IntSliceContains []int是否包含一个指定的int值。

func IsGhostInterface

func IsGhostInterface(i interface{}) bool

IsGhostInterface 判断接口是否为nil,或者指向指针是否为空。 使用指向空指针的接口去调函数,会panic。

func JsonString

func JsonString(v interface{}) string

JsonString 序列化为json,并转为字符串返回。如果序列化失败,返回空字符串。

func MapKeys2Slice

func MapKeys2Slice[K comparable, V any](m map[K]V) []K

MapKeys2Slice 提取map的key组成切片返回。

func MapValues2Slice

func MapValues2Slice[K comparable, V any](m map[K]V) []V

MapValues2Slice 提取map的value组成切片返回。

func ParseDataUrls

func ParseDataUrls(rawURL string) (mediaType string, isBase64 bool, data []byte, err error)

ParseDataUrls 解析Data Urls。 协议参考:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLshttps://en.wikipedia.org/wiki/Data_URI_scheme。 格式:data:[<mediatype>][;base64],<data>

func SliceContains

func SliceContains[T comparable](s []T, a T) bool

SliceContains 切片是否包含指定值。

func StringFromURL

func StringFromURL(ctx context.Context, rawUrl string) (string, error)

StringFromURL 从url获得字符串。 支持的scheme:file://、http://、https://、data:。 url示例:file:///etc/fstab、data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==。

func StringSliceContains

func StringSliceContains(strs []string, str string) bool

StringSliceContains []string是否包含一个指定的string值。

func SubstringsWithTags

func SubstringsWithTags(str, startTag, endTag string) []string

SubstringsWithTags 根据前后标签,找出子字符串。 比如字符串为“我是一名{[(程序员)]}”,前后标签为“{[(”和“)]}”,匹配的字符串为“程序员”。 返回元素顺序同它们在字符串内的顺序。 如果存在重复的匹配子字符串,函数返回元素也将重复。

func UnduplicatedSlice

func UnduplicatedSlice[T comparable](s []T) []T

UnduplicatedSlice 返回一个新的元素不重复的切片,新切片保留元素顺序。

func ValidateStruct

func ValidateStruct(ctx context.Context, s interface{}) error

ValidateStruct 校验结构体对象字段值。 依赖于字段validate标签。校验支持:https://github.com/go-playground/validator

Types

type Stack

type Stack struct {
	Frames []runtime.Frame
}

Stack 调用栈。

func CaptureStack

func CaptureStack(skip int) Stack

CaptureStack 捕获调用栈。 skip为0表示栈从CaptureStack开始,为1表示栈从CaptureStack的调用者开始。

func (Stack) StackTrace

func (stack Stack) StackTrace() string

StackTrace 格式化为多行字符串的堆栈跟踪信息。

func (Stack) String

func (stack Stack) String() string

String 实现fmt.Stringer。

Jump to

Keyboard shortcuts

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