util

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeFormat = time.DateTime
)

Variables

This section is empty.

Functions

func AddDir

func AddDir(path string) error

AddDir add dir

func AddFile

func AddFile(path string) error

AddFile add file

func AddFileIfNotExists

func AddFileIfNotExists(path string) error

AddFileIfNotExists add file if not exists

func AssignIfNotNil

func AssignIfNotNil[T any](dst *T, src *T)

AssignIfNotNil 检查指针是否非nil,非nil时赋值

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString 生成指定长度的随机字符串

func GetRealClientIP

func GetRealClientIP(r *http.Request) string

GetRealClientIP 获取真实的客户端IP地址

func IsExpired

func IsExpired(lastTime time.Time, duration time.Duration) bool

IsExpired 检查时间是否过期

func IsWithinDuration

func IsWithinDuration(lastTime time.Time, duration time.Duration) bool

IsWithinDuration 检查时间是否在指定时间段内

func JoinInt64s

func JoinInt64s(nums []int64) string

JoinInt64s 连接int64数组

func NewCache

func NewCache() *cache

NewCache 创建 Redis 缓存

func ParamToInt64

func ParamToInt64(c *gin.Context, key string) (int64, error)

ParamToInt64 从 URL 参数中获取 int64 类型的值.

func StructToMap

func StructToMap(obj interface{}) map[string]string

StructToMap converts a struct to a map

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value string, expiration time.Duration) error
	Delete(ctx context.Context, key string) error
	Close()
}

Cache 缓存接口

type Time

type Time time.Time

func FromTime

func FromTime(t time.Time) Time

FromTime 标准时间转换 (辅助方法)

func Now

func Now() Time

Now 获取当前时间 (实用方法)

func (Time) MarshalJSON

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

MarshalJSON 自定义时间格式化输出

func (*Time) Scan

func (t *Time) Scan(value interface{}) error

Scan 实现 GORM 的 Scanner 接口 将数据库返回的值转换为 util.Time 类型

func (Time) String

func (t Time) String() string

String 格式化输出

func (Time) ToTime

func (t Time) ToTime() time.Time

ToTime 转换为标准时间 (辅助方法)

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON 格式化自定义时间转换为 time.Time

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value 实现 GORM 的 Valuer 接口 将 util.Time 类型转换为数据库可接受的值

type TreeService

type TreeService struct {
	PrimaryKey  string
	ParentKey   string
	ExpandedKey string
	LeafKey     string
	ChildrenKey string
	Expanded    bool
	Result      []map[string]interface{}
	Level       map[interface{}]int
}

TreeService is a service for tree data.

func NewTreeService

func NewTreeService(config TreeService) *TreeService

NewTreeService returns a new TreeService.

func (*TreeService) MakeTree

func (t *TreeService) MakeTree(data []map[string]interface{}) []map[string]interface{}

MakeTree is a function for make tree data.

@param data is a data for make tree.
@return a tree data.

func (*TreeService) MakeTreeForHTML

func (t *TreeService) MakeTreeForHTML(data []map[string]interface{}) []map[string]interface{}

MakeTreeForHTML 生成线性结构, 便于HTML输出, 参数同上.

Jump to

Keyboard shortcuts

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