utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Day      = 24 * time.Hour
	Week     = 7 * Day
	Month    = 30 * Day
	Year     = 12 * Month
	LongTime = 37 * Year
)

Seconds-based time units

Variables

This section is empty.

Functions

func CreateFileIfNotExists

func CreateFileIfNotExists(filePath string) error

func CustomRelTime

func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string

CustomRelTime formats a time into a relative string.

It takes two times two labels and a table of relative time formats. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.

func FileExists

func FileExists(filePath string) (bool, error)

func FilterStringId

func FilterStringId(stringIds string, filterId int) string

func FriendlyTime

func FriendlyTime(t time.Time) string

func GetFilenamePath

func GetFilenamePath(prefix string) string

func GetRandomNickname

func GetRandomNickname() string

func GetRandomString

func GetRandomString(n int) string

func HidePhoneNumber

func HidePhoneNumber(phoneNumber string) string

func IdCompare

func IdCompare(ids1, ids2 []uint) (change []uint, increase []uint, decrease []uint)

IdCompare Change Increase Decrease

func IntSliceToString

func IntSliceToString(nums ...uint) string

func LimitString

func LimitString(str string, limit int) string

func PathExists

func PathExists(path string) (bool, error)

PathExists check path

func RelTime

func RelTime(a, b time.Time, albl, blbl string) string

RelTime formats a time into a relative string.

It takes two times and two labels. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.

RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"

func SliceFindIndex

func SliceFindIndex[T comparable](inputSlice []T, a T) int

func String2Slice

func String2Slice(s string) []string

func StringToIntSlice

func StringToIntSlice(str string) []uint

func StructToMap

func StructToMap(input any) map[string]any

func Time

func Time(then time.Time) string

Time formats a time into a relative string.

Time(someT) -> "3 weeks ago"

func TodayStartAndEndTime

func TodayStartAndEndTime() (beginTime, endTime uint)

func UintsToString

func UintsToString(numbers ...uint) string

func UniqueSlice

func UniqueSlice[T comparable](inputSlice []T) []T

func Unzip

func Unzip(src, dest string) ([]string, error)

Types

type AliOcr

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

func NewAliOcr

func NewAliOcr(accessKey, secret string) *AliOcr

func (*AliOcr) Request

func (ali *AliOcr) Request() error

func (*AliOcr) WithApiName

func (ali *AliOcr) WithApiName(apiName string)

func (*AliOcr) WithBody

func (ali *AliOcr) WithBody(body []byte)

func (*AliOcr) WithResponse

func (ali *AliOcr) WithResponse(s any)

type JsonMap

type JsonMap struct {
}

func (*JsonMap) MarshalBinary

func (j *JsonMap) MarshalBinary() (data []byte, err error)

func (*JsonMap) StructToMap

func (j *JsonMap) StructToMap(input any) map[string]any

func (*JsonMap) UnmarshalBinary

func (j *JsonMap) UnmarshalBinary(data []byte) error

type RelTimeMagnitude

type RelTimeMagnitude struct {
	D      time.Duration
	Format string
	DivBy  time.Duration
}

A RelTimeMagnitude struct contains a relative time point at which the relative format of time will switch to a new format string. A slice of these in ascending order by their "D" field is passed to CustomRelTime to format durations.

The Format field is a string that may contain a "%s" which will be replaced with the appropriate signed label (e.g. "ago" or "from now") and a "%d" that will be replaced by the quantity.

The DivBy field is the amount of time the time difference must be divided by in order to display correctly.

e.g. if D is 2*time.Minute and you want to display "%d minutes %s" DivBy should be time.Minute so whatever the duration is will be expressed in minutes.

type SensitiveTrie

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

SensitiveTrie 敏感词前缀树

func NewSensitiveTrie

func NewSensitiveTrie() *SensitiveTrie

NewSensitiveTrie 构造敏感词前缀树实例

func (*SensitiveTrie) AddWords

func (s *SensitiveTrie) AddWords(sensitiveWords ...string)

AddWords 批量添加敏感词

func (*SensitiveTrie) Match

func (s *SensitiveTrie) Match(text string) (sensitiveWords []string, replaceText string)

Match 查找替换发现的敏感词

type TrieNode

type TrieNode struct {
	Data string // 在最后一个节点保存完整的一个内容
	End  bool   // 标识是否最后一个节点
	// contains filtered or unexported fields
}

TrieNode 敏感词前缀树节点

Directories

Path Synopsis
Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.
Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.

Jump to

Keyboard shortcuts

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