utils

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CeilingToDay

func CeilingToDay(t time.Time) time.Time

CeilingToDay 将日期改为日的结束。

func Compute added in v0.0.3

func Compute[T comparable, R any](a map[T]R, k T, r0 R, fn func(T, R) R) R

func DiffDays

func DiffDays(st, et time.Time) float64

func FileExists added in v0.0.10

func FileExists(fn string) (bool, error)

func IsWorkingDay

func IsWorkingDay(t time.Time) bool

IsWorkingDay 判断指定日是否是工作日。

func LocalDate added in v0.0.3

func LocalDate(year int, month time.Month, day int) time.Time

LocalDate 获取指定的本地日期。

func ParseDate

func ParseDate(s string, d time.Time) time.Time

ParseDate 解析日期。如果解析不成功则返回默认值。

func RecoverAsEleErr

func RecoverAsEleErr[T any](ch chan<- Ele[T])

func Sha256Salt

func Sha256Salt(s string) string

Sha256Salt 加盐然后获取Sha256的hash值。

func SplitAsInt

func SplitAsInt[T int | int8 | int16 | int32 | int64](s, sep string) []T

SplitAsInt

func Sum

func Sum[T any, R int | int8 | int16 | int32 | int64 | float32 | float64](a []T, r0 R, fn func(T) R) R

func ToStr

func ToStr(o any, ds string) string

ToStr 将对象转化为字符串。 如果o表示nil则返回ds。

func Today

func Today() time.Time

Today 获取表示今天0点0分0秒的日期。

func TruncateToDay

func TruncateToDay(t time.Time) time.Time

TruncateToDay 将日期截断到日。

Types

type AtomicTime

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

func NewAtomicTime

func NewAtomicTime(t time.Time) *AtomicTime

func (*AtomicTime) CompareAndMax

func (t *AtomicTime) CompareAndMax(oa ...time.Time) bool

func (*AtomicTime) CompareAndMin

func (t *AtomicTime) CompareAndMin(oa ...time.Time) bool

func (*AtomicTime) Time

func (t *AtomicTime) Time() time.Time

type Boolean added in v0.0.11

type Boolean struct {
	Valid bool
	Bool  bool
}

func (Boolean) MarshalJSON added in v0.0.11

func (b Boolean) MarshalJSON() ([]byte, error)

func (Boolean) String added in v0.0.11

func (b Boolean) String() string

func (*Boolean) UnmarshalJSON added in v0.0.11

func (b *Boolean) UnmarshalJSON(data []byte) error

type Ele

type Ele[T any] struct {
	// contains filtered or unexported fields
}

func NewEle

func NewEle[T any](t *T) Ele[T]

func NewEleErr

func NewEleErr[T any](err any) Ele[T]

func (*Ele[T]) Data

func (e *Ele[T]) Data() *T

func (*Ele[T]) Err

func (e *Ele[T]) Err() error

type ISODate added in v0.0.6

type ISODate time.Time

func (ISODate) MarshalJSON added in v0.0.6

func (t ISODate) MarshalJSON() ([]byte, error)

func (ISODate) String added in v0.0.6

func (t ISODate) String() string

func (*ISODate) UnmarshalJSON added in v0.0.6

func (t *ISODate) UnmarshalJSON(data []byte) error

type RollingFileWriter added in v0.0.10

type RollingFileWriter struct {
	Base   string // 日志文件夹。
	Prefix string // 日志文件前缀。
	// contains filtered or unexported fields
}

滚动文件日志记录器。

var (
	// 默认的滚动文件日志记录器。
	DefaultRollingFileWriter *RollingFileWriter = &RollingFileWriter{
		Base:   "./log",
		Prefix: "app",
	}
)

func (*RollingFileWriter) Write added in v0.0.10

func (w *RollingFileWriter) Write(p []byte) (n int, err error)

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set 表示一个集合。

func NewSet

func NewSet[T comparable](t ...T) *Set[T]

func (*Set[T]) Add

func (ss *Set[T]) Add(t T)

func (*Set[T]) AllKeys added in v0.0.9

func (ss *Set[T]) AllKeys() []T

func (*Set[T]) Contains

func (ss *Set[T]) Contains(t T) bool

func (*Set[T]) ContainsAny

func (ss *Set[T]) ContainsAny(t ...T) bool

func (*Set[T]) IsEmpty

func (ss *Set[T]) IsEmpty() bool

func (*Set[T]) Len

func (ss *Set[T]) Len() int

func (*Set[T]) Remove

func (ss *Set[T]) Remove(t T)

func (*Set[T]) String added in v0.0.9

func (ss *Set[T]) String() string

type Timestamp added in v0.0.4

type Timestamp time.Time

func (Timestamp) MarshalJSON added in v0.0.4

func (t Timestamp) MarshalJSON() ([]byte, error)

func (Timestamp) String added in v0.0.6

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON added in v0.0.4

func (t *Timestamp) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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