api

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 19 Imported by: 48

Documentation

Index

Constants

View Source
const (
	// CACHE_DIR_MODE 目录权限
	CACHE_DIR_MODE os.FileMode = 0755
	// CACHE_FILE_MODE 文件权限
	CACHE_FILE_MODE os.FileMode = 0644

	// DEBUG 调试开关
	DEBUG = false
	// CACHE_REPLACE 文件替换模式, 会用到os.TRUNC
	CACHE_REPLACE = os.O_CREATE | os.O_RDWR | os.O_TRUNC
	// CACHE_UPDATE 更新
	CACHE_UPDATE = os.O_CREATE | os.O_WRONLY
)
View Source
const (
	IGNORE_FLOAT = true
)
View Source
const (
	YearOnly = "2006" // 日期格式仅输出"年"
)

Variables

View Source
var (
	ErrInvalidCopyDestination = errors.New("copy destination is invalid")
	ErrInvalidCopyFrom        = errors.New("copy from is invalid")
	ErrMapKeyNotMatch         = errors.New("map's key type doesn't match")
	ErrNotSupported           = errors.New("not supported")
)

Functions

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String 字节数组转字符串

func ChanIsClosed

func ChanIsClosed(ch any) bool

ChanIsClosed 判断channel是否关闭

func CheckFilepath

func CheckFilepath(filename string, notExistToCreate ...bool) error

CheckFilepath

检查filename 文件路径, 如果不存在就创建

func CloseQuietly

func CloseQuietly(closer io.Closer)

CloseQuietly 关闭io, 忽略错误

func Convert

func Convert(data []string, v interface{}) error

func Copy

func Copy(toValue interface{}, fromValue interface{}) (err error)

Copy copy things

func CopyWithOption

func CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error)

CopyWithOption copy with option

func DateZero added in v1.6.1

func DateZero(t time.Time) time.Time

DateZero t 的0点0分0秒

func DifferDays added in v1.6.1

func DifferDays(t1, t2 time.Time) int

DifferDays 计算天数差

从 t1 回到 t2 需要多少天

func EndsWith

func EndsWith(str string, suffixes []string) bool

EndsWith 字符串前缀判断

func Filter

func Filter[S ~[]E, E any](slice S, condition func(E) bool) S

Filter slice过滤

func Float64s

func Float64s(a *[]float64)

Float64s removes duplicate elements from a sorted slice of float64s.

func Float64sAreUnique

func Float64sAreUnique(a []float64) bool

Float64sAreUnique tests whether a slice of float64s is sorted and its elements are unique.

func GetMonthDay added in v1.6.1

func GetMonthDay() (string, string)

GetMonthDay 获得当前月的初始和结束日期

func GetQuarterDay added in v1.6.1

func GetQuarterDay(months ...int) (string, string)

GetQuarterDay 获得当前季度的初始和结束日期

func GetWeekDay added in v1.6.1

func GetWeekDay() (string, string)

GetWeekDay 获得当前周的初始和结束日期

func Ints

func Ints(a *[]int)

Ints removes duplicate elements from a sorted slice of ints.

func IntsAreUnique

func IntsAreUnique(a []int) bool

IntsAreUnique tests whether a slice of ints is sorted and its elements are unique.

func IsEmpty

func IsEmpty(s string) bool

IsEmpty Code to test if string is empty

func IsUniqued

func IsUniqued(data sort.Interface) bool

IsUniqued reports whether the elements in data are sorted and unique.

func IsWorkday added in v1.6.1

func IsWorkday(t time.Time) bool

IsWorkday 是否工作日

func KebabCase

func KebabCase(s string) string

KebabCase converts a string into kebab case.

func LowerCamelCase

func LowerCamelCase(s string) string

LowerCamelCase converts a string into camel case starting with a lower case letter.

func ParseFloat

func ParseFloat(s string) float64

func ParseInt

func ParseInt(s string) int64

func ParseTime added in v1.6.1

func ParseTime(timestr string) (time.Time, error)

ParseTime 解析时间差

func ParseUint

func ParseUint(s string) uint64

func Reverse

func Reverse[S ~[]E, E any](s S) S

Reverse 反转切片

func SnakeCase

func SnakeCase(s string) string

SnakeCase converts a string into snake case.

func Sort

func Sort(data Interface)

Sort sorts and removes duplicate entries from data.

func StartsWith

func StartsWith(str string, prefixes []string) bool

StartsWith 字符串前缀判断

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes 字符串转字节数组

func Strings

func Strings(a *[]string)

Strings removes duplicate elements from a sorted slice of strings.

func StringsAreUnique

func StringsAreUnique(a []string) bool

StringsAreUnique tests whether a slice of strings is sorted and its elements are unique.

func ToCamelCase

func ToCamelCase(kebab string) (camelCase string)

ToCamelCase 转驼峰

func ToFront

func ToFront(data sort.Interface) (n int)

ToFront reports the number of unique elements of data which it moves to the first n positions. It assumes sort.IsSorted(data).

func ToString

func ToString(value interface{}) string

ToString converts a value to string.

func Unique

func Unique(data Interface)

Unique removes duplicate elements from data. It assumes sort.IsSorted(data).

func UpperCamelCase

func UpperCamelCase(s string) string

UpperCamelCase converts a string into camel case starting with a upper case letter.

func UpperKebabCase

func UpperKebabCase(s string) string

UpperKebabCase converts a string into kebab case with capital letters.

func UpperSnakeCase

func UpperSnakeCase(s string) string

UpperSnakeCase converts a string into snake case with capital letters.

Types

type Float64Slice

type Float64Slice struct{ P *[]float64 }

Float64Slice attaches the methods of Interface to []float64.

func (Float64Slice) Len

func (p Float64Slice) Len() int

func (Float64Slice) Less

func (p Float64Slice) Less(i, j int) bool

func (Float64Slice) Swap

func (p Float64Slice) Swap(i, j int)

func (Float64Slice) Truncate

func (p Float64Slice) Truncate(n int)

type IntSlice

type IntSlice struct{ P *[]int }

IntSlice attaches the methods of Interface to []int.

func (IntSlice) Len

func (p IntSlice) Len() int

func (IntSlice) Less

func (p IntSlice) Less(i, j int) bool

func (IntSlice) Swap

func (p IntSlice) Swap(i, j int)

func (IntSlice) Truncate

func (p IntSlice) Truncate(n int)

type Interface

type Interface interface {
	sort.Interface

	// Truncate reduces the length to the first n elements.
	Truncate(n int)
}

Interface Types that implement unique.Interface can have duplicate elements removed by the functionality in this package.

type Option

type Option struct {
	// setting this value to true will ignore copying zero values of all the fields, including bools, as well as a
	// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
	IgnoreEmpty bool
	DeepCopy    bool
}

Option sets copy options

type StringSlice

type StringSlice struct{ P *[]string }

StringSlice attaches the methods of Interface to []string.

func (StringSlice) Len

func (p StringSlice) Len() int

func (StringSlice) Less

func (p StringSlice) Less(i, j int) bool

func (StringSlice) Swap

func (p StringSlice) Swap(i, j int)

func (StringSlice) Truncate

func (p StringSlice) Truncate(n int)

Jump to

Keyboard shortcuts

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