api

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 22 Imported by: 48

Documentation

Index

Constants

View Source
const (
	// DateFormat  日期格式 yyyy-MM-dd
	DateFormat = "2006-01-02"
	// DateFormat2 日期格式 yyyyMMdd
	DateFormat2 = "20060102"
	// DateFormat3 日期格式 yyMMdd
	DateFormat3 = "060102"

	// TimeFormat 时间格式 yyyy-MM-dd HH:mm:ss
	TimeFormat = "2006-01-02 15:04:05"
	// TimeFormat2 时间格式 yyyyMMddHHmmss
	TimeFormat2 = "20060102150405"
	// Timestamp 时间戳 - 毫秒 时间格式 yyyy-MM-dd HH:mm:ss.SSS
	Timestamp = "2006-01-02 15:04:05.000"

	// TimeOnly 时分秒
	TimeOnly = time.TimeOnly
	// TimeAndMillisecond 时分秒毫
	TimeAndMillisecond = "15:04:05.000"

	PathDate = "20060102"   // 路径中的日期格式
	TextDate = "2006-01-02" // 数据中的日期格式
)
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 (
	DefaultTagName = "dataframe"
)
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")
)
View Source
var (
	ErrRangeInvalid      = errors.New("range invalid")
	ErrLengthUndefined   = errors.New("limit undefined")
	ErrLengthNotProvided = errors.New("end is nil so length must be provided")
)
View Source
var (
	ErrDateFormat = errors.New("日期格式无法确定")
)
View Source
var (
	ErrInvalidFileStat = errors.New("invalid file stat")
)
View Source
var (
	ErrNotConvert = errors.New("can not Convert")
)

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[T any](data []string, v *T) error

Convert 将字符串数组按照下标的序号反射给一个结构体

func Copy

func Copy[T any, S any](to *T, from *S) (err error)

Copy copy things

func CopyWithOption

func CopyWithOption(toValue any, fromValue any, opt Option) (err error)

CopyWithOption copy with option

func CsvToSlices added in v1.6.7

func CsvToSlices[S ~[]E, E any](filename string, pointer *S) error

CsvToSlices CSV文件转struct切片

func DateZero added in v1.6.1

func DateZero(t time.Time) time.Time

DateZero t 的0点0分0秒

func Decimal added in v1.20.1

func Decimal(value float64, digits ...int) float64

Decimal 保留小数点四舍五入

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 Export added in v1.11.8

func Export(resources embed.FS, source, target string) error

Export 导出内嵌资源文件

func FileExist added in v1.6.8

func FileExist(path string) bool

FileExist 路径是否存在

func FileIsValid added in v1.6.8

func FileIsValid(path string) bool

FileIsValid 检查文件是否有效

func Filter

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

Filter slice过滤

func GetConcreteContainerInnerType added in v1.19.7

func GetConcreteContainerInnerType(in reflect.Type) (inInnerWasPointer bool, inInnerType reflect.Type)

func GetConcreteReflectValueAndType added in v1.19.7

func GetConcreteReflectValueAndType(in any) (reflect.Value, reflect.Type)

func GetMonthDay added in v1.6.1

func GetMonthDay(date ...string) (string, string)

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

func GetQuarterByDate added in v1.7.6

func GetQuarterByDate(date string, diffQuarters ...int) (quarter, first, last string)

GetQuarterByDate 通过给定的日期 获得日期所在财报的季度、初始以及结束日期

diffQuarters 季度偏移数, 大于0前移diffQuarters个季度, 小于0后移diffQuarters个季度, 默认为当前季度

func GetQuarterDay added in v1.6.1

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

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

func GetQuarterDayByDate added in v1.7.4

func GetQuarterDayByDate(date string, diffQuarters ...int) (firstOfQuarter, lastOfQuarter string)

GetQuarterDayByDate 通过给定的日期 获得日期所在上一个季度的初始和结束日期

diffQuarters 季度偏移数, 大于0前移diffQuarters个季度, 小于0后移diffQuarters个季度, 默认为当前季度

func GetWeekDay added in v1.6.1

func GetWeekDay(date ...string) (string, string)

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

func IsEmpty

func IsEmpty(s string) bool

IsEmpty Code to test if string is empty

func IsErrorType added in v1.19.7

func IsErrorType(outType reflect.Type) bool

func IsNaN added in v1.20.1

func IsNaN(f float64) bool

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 Keys added in v1.16.1

func Keys[M ~map[K]V, K comparable, V any](m M) []K

Keys returns the keys of the map m. The keys will be in an indeterminate order.

func LowerCamelCase

func LowerCamelCase(s string) string

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

func NanosecondToTime added in v1.15.9

func NanosecondToTime(nanoseconds int64) time.Time

func OpenEmbed added in v1.11.8

func OpenEmbed(resources embed.FS, filename string) (fs.File, error)

OpenEmbed 打开嵌入式文件

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 SecondToTime added in v1.16.1

func SecondToTime(sec int64) time.Time

SecondToTime 把秒级的时间戳转为time格式

func SliceSort added in v1.6.5

func SliceSort[S ~[]E, E any](slice S, less func(a, b E) bool)

SliceSort slice排序

func SliceUnique added in v1.6.5

func SliceUnique[S ~[]E, E any](slice S, compare func(a E, b E) int) S

func SlicesToCsv added in v1.6.7

func SlicesToCsv[S ~[]E, E any](filename string, s S) error

SlicesToCsv struct切片转csv文件

func SnakeCase

func SnakeCase(s string) string

SnakeCase converts a string into snake case.

func StartsWith

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

StartsWith 字符串前缀判断

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes 字符串转字节数组

func ToCamelCase

func ToCamelCase(kebab string) (camelCase string)

ToCamelCase 转驼峰

func ToString

func ToString(value interface{}) string

ToString converts a value to string.

func Touch added in v1.17.9

func Touch(filename string) error

Touch 创建一个空文件

func Unique

func Unique[E canUnique](s []E) []E

Unique 切片去重, 按照升序排序

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.

func Values added in v1.16.1

func Values[M ~map[K]V, K comparable, V any](m M) []V

Values returns the values of the map m. The values will be in an indeterminate order.

Types

type FileStat added in v1.15.9

type FileStat struct {
	CreationTime   time.Time
	LastAccessTime time.Time
	LastWriteTime  time.Time
}

func GetFileStat added in v1.15.9

func GetFileStat(name string) (*FileStat, error)

GetFileStat 获取文件状态(创建,修改和访问时间)

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 ScopeLimit added in v1.7.0

type ScopeLimit struct {
	Start *int
	End   *int
}

ScopeLimit is used to specify a range. Both Start and End are inclusive. A nil value means no limit, so a Start of nil means 0 and an End of nil means no limit. The End value must always be equal to or larger than Start. Negative values are acceptable. A value of -2 means the second last row.

func IntsToRanges added in v1.7.0

func IntsToRanges(ints []int) []ScopeLimit

IntsToRanges will convert an already (ascending) ordered list of ints to a slice of Ranges.

Example:

import "sort"
ints := []int{2,4,5,6,8,10,11,45,46}
sort.Ints(ints)

fmt.Println(IntsToRanges(ints))
// Output: R{2,2}, R{4,6}, R{8,8}, R{10,11}, R{45,46}

func RangeFinite added in v1.7.0

func RangeFinite(start int, end ...int) ScopeLimit

RangeFinite returns a ScopeLimit that has a finite span.

func (*ScopeLimit) Limited added in v1.20.0

func (r *ScopeLimit) Limited(length int) (start, end int)

func (*ScopeLimit) Limits added in v1.7.0

func (r *ScopeLimit) Limits(length int) (s int, e int, _ error)

Limits is used to return the start and end limits of a ScopeLimit object for a given Dataframe or Series with length number of rows.

func (*ScopeLimit) NRows added in v1.7.0

func (r *ScopeLimit) NRows(length ...int) (int, error)

NRows returns the number of rows contained by ScopeLimit. If End is nil, then length must be provided.

func (ScopeLimit) String added in v1.7.0

func (r ScopeLimit) String() string

String implements Stringer interface.

Jump to

Keyboard shortcuts

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