yu

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

yu

Golang 开发辅助库

导入

go get gitee.com/yscsky/yu@main

代码自动生成工具

使用说明

Documentation

Index

Constants

View Source
const (
	// TimeLayout1 2006-01-02 15:04:05
	TimeLayout1 = "2006-01-02 15:04:05"
	// TimeLayout2 2006-01-02
	TimeLayout2 = "2006-01-02"
	// TimeLayout3 15:04:05
	TimeLayout3 = "15:04:05"
	// TimeLayout4 20060102150405
	TimeLayout4 = "20060102150405"
	// TimeLayout5 20060102
	TimeLayout5 = "20060102"
	// TimeLayout6 150405
	TimeLayout6 = "150405"
	// TimeLayout7 2006.01.02
	TimeLayout7 = "2006.01.02"
	// TimeLayout8 2006/01/02
	TimeLayout8 = "2006/01/02"
)

timestamp format layout

Variables

This section is empty.

Functions

func Cost added in v0.2.1

func Cost(msg string) func()

Cost 耗时检测

func CreateFolder

func CreateFolder(path string) error

CreateFolder 创建path路径的文件夹

func Errf

func Errf(fomart string, v ...any)

Errf 固定格式打印错误信息

func GetCaller

func GetCaller(d int) (string, int)

GetCaller 获取调用方法名

func GetRealIP

func GetRealIP(req *http.Request) string

GetRealIP 获取真实IP

func HeadSeparator

func HeadSeparator(path string) string

HeadSeparator 确保path以/开头

func LoadJSON

func LoadJSON(name string, data any) error

LoadJSON 解析name.json

func LoadOrSaveJSON

func LoadOrSaveJSON(name string, res any, def func() any) (err error)

LoadOrSaveJSON 解析name.json,不存在保存

func LoadOrSaveToml

func LoadOrSaveToml(name string, data any, def func() any) (err error)

LoadOrSaveToml 解析name.toml,不存在保存

func LoadOrSaveYaml added in v0.2.1

func LoadOrSaveYaml(name string, data any, def func() any) (err error)

LoadOrSaveYaml 解析name.yaml,不存在保存

func LoadToml

func LoadToml(name string, data any) error

LoadToml 解析name.toml

func LoadYaml added in v0.2.1

func LoadYaml(name string, data any) error

LoadToml 解析name.yaml

func LogErr

func LogErr(err error, msg string)

LogErr 固定格式打印error

func Logf

func Logf(fomart string, v ...any)

Logf 固定格式打印信息

func MD5

func MD5(src string) string

MD5 获取字符串的MD5

func RandomString

func RandomString(n int) string

RandomString 生成n长度的字符串

func Run

func Run(app IApp)

Run 运行服务

func SaveJSON

func SaveJSON(name string, data any) error

SaveJSON 保存到name.json

func SaveToml

func SaveToml(name string, data any) error

SaveToml 保存到name.toml

func SaveYaml added in v0.2.1

func SaveYaml(name string, data any) error

SaveYaml 保存到name.yaml

func TailSeparator

func TailSeparator(path string) string

TailSeparator 确保path以/结尾

func UUID

func UUID() string

UUID 生成没有-的UUID

func Warnf added in v0.0.2

func Warnf(fomart string, v ...any)

Warnf 固定格式打印警告信息

Types

type IApp added in v0.1.9

type IApp interface {
	Name() string
	Servers() []IServer
	OnStart() bool
	OnStop()
}

IApp 应用实现接口

type IQueue added in v0.2.1

type IQueue interface {
	Start()
	Stop()
	Submit(args any, sync bool)
}

IQueue 队列接口

func NewQueue

func NewQueue(size, count int, deal func(any)) IQueue

NewQueue 新建队列

type IServer added in v0.1.9

type IServer interface {
	OnStart() bool
	OnStop()
	Info() string
}

IServer 服务实现接口

type QueueManager added in v0.0.2

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

QueueManager 队列管理器

func NewQueueManager added in v0.0.2

func NewQueueManager() *QueueManager

NewQueueManager 新建队列管理器

func (*QueueManager) AddQueue added in v0.0.2

func (qm *QueueManager) AddQueue(q IQueue)

AddQueue 管理器中添加队列

func (*QueueManager) GetQueue added in v0.0.2

func (qm *QueueManager) GetQueue(i int) IQueue

GetQueue 管理器中获取队列

func (*QueueManager) PushQueue added in v0.0.2

func (qm *QueueManager) PushQueue(i int, args interface{})

PushQueue 添加任务到管理器队列中

func (*QueueManager) StartQueues added in v0.2.1

func (qm *QueueManager) StartQueues()

StartQueue 管理器启动所有队列

type Serial

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

Serial 序列生成器

func NewSerial

func NewSerial(reset int) *Serial

NewSerial 创建Serial

func (*Serial) Get

func (s *Serial) Get() int

Get 获取序列值

func (*Serial) Reset

func (s *Serial) Reset(c int)

Reset 重置计数

func (*Serial) Start

func (s *Serial) Start()

Start 开始序列生成器

type TStamp

type TStamp int64

TStamp custom type for int64

func NewStampTime

func NewStampTime(te time.Time) TStamp

NewStampTime new TStamp by time.Time

func NewStrStamp

func NewStrStamp(ts string) TStamp

NewStrStamp new TStamp by time string

func NewTimeStamp

func NewTimeStamp(ts int64) TStamp

NewTimeStamp new TStamp

func (TStamp) Format

func (t TStamp) Format(layout string) string

Format get format time

func (TStamp) GoString

func (t TStamp) GoString() string

GoString implement GoStringer

func (TStamp) Int64

func (t TStamp) Int64() int64

Int64 get int64 value

func (TStamp) MarshalJSON

func (t TStamp) MarshalJSON() (buf []byte, err error)

MarshalJSON implement Marshaler

func (TStamp) String

func (t TStamp) String() string

String implement Stringer

func (TStamp) Time

func (t TStamp) Time() time.Time

Time get time.Time

func (*TStamp) UnmarshalJSON

func (t *TStamp) UnmarshalJSON(b []byte) error

UnmarshalJSON implement Unmarshaler

type XmlMap

type XmlMap map[string]string

XmlMap xml转换map

func (XmlMap) MarshalXML

func (m XmlMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the map to XML

func (*XmlMap) UnmarshalXML

func (m *XmlMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a map of string to strings

Jump to

Keyboard shortcuts

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