misc

package
v0.0.0-...-2580d5c Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 29 Imported by: 5

README

不可在此文件添加外部引用

Documentation

Index

Constants

View Source
const (
	FileUnitJson = iota
	FileUnitToml
)
View Source
const (
	ErrCtxNil       = ErrStr("ctx is nil")
	ErrParamInvalid = ErrStr("param invalid")
)
View Source
const (
	ErrStop     = ErrStr("stop")
	ErrNotStart = ErrStr("not start")
)
View Source
const (
	ErrNotInit    = ErrStr("not init")
	ErrRepeatInit = ErrStr("repeat init")
)
View Source
const (
	ErrNil = ErrStr("nil")
)

Variables

View Source
var GJsonTool = &JsonTool{}
View Source
var GTomlTool = &TomlTool{}

Functions

func AddProperty

func AddProperty[T Property](p T, properties ...T) T

func Black

func Black(str string) string

func Blue

func Blue(str string) string

func CheckSetDefault

func CheckSetDefault(m *map[string]interface{}, key string, value interface{}) bool

CheckSetDefault 检查默认值是否存在,若否则置上。返回默认值是否存在

func Clear

func Clear()

Clear 清空屏幕

func ClearIOBuffer

func ClearIOBuffer()

func CmdPy

func CmdPy(pythonPath string, cmdArgs ...string) (result string, err error)

func CopyFile

func CopyFile(dstName, srcName string) (written int64, err error)

CopyFile 复制文件

func CreateProperty

func CreateProperty[T Property](properties ...T) T

func CutToStrings

func CutToStrings(str string) []string

func Cyan

func Cyan(str string) string

func DeleteFileAndChild

func DeleteFileAndChild(path string) error

func GetFileContent

func GetFileContent(path string) string

func GetIndexPage

func GetIndexPage(index int, pageSize int, pageBegin1 bool) (page int, pageIndex int)

func GetMaxPage

func GetMaxPage(total int, pageSize int, pageBegin1 bool) (maxPage int)

func GetNameFromPath

func GetNameFromPath(path string) string

func GetPageIndexOriIndex

func GetPageIndexOriIndex(index int, page int, pageSize int, pageBegin1 bool) int

func GetPageStartEnd

func GetPageStartEnd(page int, pageSize int, total int, pageBegin1 bool) (pageStart int, pageEnd int)

func GetPicLinkFromStr

func GetPicLinkFromStr(mdStr string) []string

GetPicLinkFromStr 从字符串中提取所有的图片外链

func GetRealDir

func GetRealDir() string

GetRealDir 返回当前可执行程序的真正目录,如果是软链接,则返回软链接指向的文件的目录

func GetTimeStr

func GetTimeStr() string

GetTimeStr 返回当前的时间,格式为2006-01-02 15:04:05

func Green

func Green(str string) string

func HasOneProperty

func HasOneProperty[T Property](p T, properties ...T) bool

func HasProperty

func HasProperty[T Property](p T, properties ...T) bool

func Init

func Init(h *ArrayHeap)

func Input

func Input(hint string, len int, a ...interface{}) error

func InputInt

func InputInt(notice string) int

func InputStr

func InputStr(len int) string

func InputString

func InputString(notice string) string

func InputStringWithSpace

func InputStringWithSpace(notice string) []string

func IsLegalOutURL

func IsLegalOutURL(url string) bool

IsLegalOutURL 判断是否是合法的外链

func JoinErr

func JoinErr(errs ...error) error

func Len

func Len(h *ArrayHeap) int

func MarkdownToHTML

func MarkdownToHTML(md string) string

MarkdownToHTML 提供markdown到html的功能

func MinMax

func MinMax(array []CanCompare) (min CanCompare, minIndex int, max CanCompare, maxIndex int)

MinMax 求一个CanCompare切片的最大最小值

func MinMaxInt

func MinMaxInt(array []int) (min int, minIndex int, max int, maxIndex int)

MinMaxInt 求一个int切片的最大最小值

func MinMaxSlice

func MinMaxSlice[T cmp.Ordered](array []T) (min T, minIndex int, max T, maxIndex int)

MinMaxSlice 求一个切片的最大最小值

func MinMaxUInt

func MinMaxUInt(array []uint32) (min uint32, minIndex int, max uint32, maxIndex int)

MinMaxUInt 求一个int切片的最大最小值

func PathExist

func PathExist(path string) bool

PathExist 返回文件或目录是否存在

func Purple

func Purple(str string) string

func Push

func Push(h *ArrayHeap, x Comparable)

func ReadAllDir

func ReadAllDir(root string) []string

ReadAllDir 返回root目录下所有的目录,当出现错误时返回nil,否则至少返回空

func ReadAllFile

func ReadAllFile(root string) []string

ReadAllFile 返回root目录下所有的目录,当出现错误时返回nil,否则至少返回空数组

func ReadGBKFileLine

func ReadGBKFileLine(addr string) (string, error)

func Red

func Red(str string) string

func ReplaceUnicodeEscapes

func ReplaceUnicodeEscapes(input string) string

func Stop

func Stop()

func Str2list

func Str2list(s string) []string

Str2list 将json风格的数组字符串s转换为字符串

func White

func White(str string) string

func WriteGBKFileLine

func WriteGBKFileLine(addr string, content string) error

func Yellow

func Yellow(str string) string

Types

type ArrayHeap

type ArrayHeap []Comparable

func (*ArrayHeap) Len

func (h *ArrayHeap) Len() int

func (*ArrayHeap) Less

func (h *ArrayHeap) Less(i, j int) bool

func (*ArrayHeap) Pop

func (h *ArrayHeap) Pop() interface{}

func (*ArrayHeap) Push

func (h *ArrayHeap) Push(x interface{})

func (*ArrayHeap) Swap

func (h *ArrayHeap) Swap(i, j int)

type CanCompare

type CanCompare interface {
	Less(CanCompare) bool
}

type CmdMenu

type CmdMenu struct {
	HisList      []*SingleMenu // 方便完成返回到上一步
	HisListIndex int
	// contains filtered or unexported fields
}

func (*CmdMenu) Init

func (m *CmdMenu) Init(root *SingleMenu)

func (*CmdMenu) Run

func (m *CmdMenu) Run()

type Comparable

type Comparable interface {
	Less(other Comparable) bool
}

func Pop

func Pop(h *ArrayHeap) Comparable

func Remove

func Remove(h *ArrayHeap, i int) Comparable

func Top

func Top(h *ArrayHeap) Comparable

type ErrStr

type ErrStr string

func (ErrStr) Error

func (e ErrStr) Error() string

type Error

type Error struct {
	Reason string
}

Error 是基础Error类,仅包含一个失败原因字符串

func (Error) Error

func (e Error) Error() string

type FileUnit

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

FileUnit 是一个可以用于任意类型的非一次性序列化工具 可以将变量的指针与文件中的实际值关联 NewFileUnit 会将结构体绑定某一个文件地址,之后可以通过Load和Save来进行读写

func NewFileUnit

func NewFileUnit[T any](unitType FileUnitType, addr string) *FileUnit[T]

NewFileUnit 初始化文件单元

func (*FileUnit[T]) Copy

func (t *FileUnit[T]) Copy() T

Copy 复制一份向外传达,请注意类型内部是否存在指针

func (*FileUnit[T]) Load

func (t *FileUnit[T]) Load() error

Load 从addr对应的文件中载入数据

func (*FileUnit[T]) SafeUseData

func (t *FileUnit[T]) SafeUseData(f func(any), isWrite bool)

SafeUseData 线程安全的使用数据的函数

func (*FileUnit[T]) Save

func (t *FileUnit[T]) Save() error

Save 序列化数据结构到文件

func (*FileUnit[T]) SaveOther

func (t *FileUnit[T]) SaveOther(addr string) error

SaveOther 序列化数据结构到某个文件

type FileUnitType

type FileUnitType int

type FuncQueueCaller

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

func (*FuncQueueCaller) Exit

func (q *FuncQueueCaller) Exit() bool

func (*FuncQueueCaller) Init

func (q *FuncQueueCaller) Init(num int, paraNum int)

func (*FuncQueueCaller) PushFunc

func (q *FuncQueueCaller) PushFunc(f func()) bool

type GoLimit

type GoLimit struct {
	InitTag
	// contains filtered or unexported fields
}

GoLimit 并发执行限流器 如果超过限制上线,会阻塞 如果一个函数跨越两个周期,会阻塞 init 后调用 start使用 停止通过ctx实现或直接调用 不支持stop后重新start

func (*GoLimit) Call

func (m *GoLimit) Call(f func()) error

func (*GoLimit) Init

func (m *GoLimit) Init(setting GoLimitSetting, ctx context.Context) error

func (*GoLimit) Start

func (m *GoLimit) Start() error

func (*GoLimit) Stop

func (m *GoLimit) Stop() error

type GoLimitSetting

type GoLimitSetting struct {
	TimeInterval         time.Duration // 每隔多少秒重置一次
	EveryIntervalCallNum int32         // 每个周期允许执行多少次
}

GoLimitSetting 并发执行限流器设置

type IFileRwUnit

type IFileRwUnit interface {
	Read(addr string, pData interface{}) error
	Write(addr string, pData interface{}) error
}

type ISyncProtoRec

type ISyncProtoRec interface {
	proto.Message
	GetRecallID() uint32
}

type ISyncProtoSend

type ISyncProtoSend interface {
	proto.Message
	GetRecallID() uint32 // 为了反射修改RecallID,其proto文件中必须有RecallID字段,则必有GetRecallID方法
}

type InitTag

type InitTag struct {
	Init bool
}

func (*InitTag) IsInitialized

func (receiver *InitTag) IsInitialized() bool

func (*InitTag) SetInitialized

func (receiver *InitTag) SetInitialized()

type JsonTool

type JsonTool struct{}

func (*JsonTool) Read

func (*JsonTool) Read(addr string, pData interface{}) error

func (*JsonTool) Write

func (*JsonTool) Write(addr string, pData interface{}) error

type LoadTag

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

func (*LoadTag) IsLoad

func (t *LoadTag) IsLoad() bool

func (*LoadTag) Loaded

func (t *LoadTag) Loaded()

type LosePicUrlError

type LosePicUrlError struct {
	Error
	URLs []string
}

type MarkdownTool

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

func (*MarkdownTool) AddContent

func (m *MarkdownTool) AddContent(content string)

func (*MarkdownTool) AddList

func (m *MarkdownTool) AddList(content string, lv int)

func (*MarkdownTool) AddMd

func (m *MarkdownTool) AddMd(md string)

func (*MarkdownTool) AddReference

func (m *MarkdownTool) AddReference(reference string)

func (*MarkdownTool) AddTitle

func (m *MarkdownTool) AddTitle(title string, lv int)

func (*MarkdownTool) ToStr

func (m *MarkdownTool) ToStr() string

type Property

type Property interface {
	~int | ~int32 | ~int64 | ~uint32 | ~uint64 | ~uint | ~uint8 | ~uint16 | ~int8 | ~int16
}

type SingleMenu

type SingleMenu struct {
	Name    string // 项目名
	F       func() // 可以被call的节点
	SubMenu []*SingleMenu
}

type StringTag

type StringTag struct {
	Tag string
	Num int
}

type Sync

type Sync struct {
	ID atomic.Uint32
	// contains filtered or unexported fields
}

func (*Sync) OnRecResult

func (s *Sync) OnRecResult(data ISyncProtoRec) error

func (*Sync) Wait

func (s *Sync) Wait(send func(cConn net.Conn, areaID uint32, data ISyncProtoSend) error, cConn net.Conn, areaID uint32, data ISyncProtoSend, timeout time.Duration) (ISyncProtoRec, error)

type TJsonTool

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

TJsonTool 是对于json文件的抽象,可以用匿名组合的方式进行二次包装

请注意已经被废弃,请使用JsonTool与FileUnit

func NewTJsonTool

func NewTJsonTool(addr string, pData interface{}) *TJsonTool

NewTJsonTool 针对传入的数据初始化,在此时会载入数据。如果传入地址为空则不进行载入 !!!!!!!!当传入值也能正常工作,但是传入指针可以避免浪费了右值,并且可以直接对结构体进行操作!!!!!!!

func (*TJsonTool) Data

func (t *TJsonTool) Data() interface{}

Data 从数据结构中取出指针,此时应该用.(*TYPE)转换为某指针继续使用

func (*TJsonTool) Load

func (t *TJsonTool) Load(addr string) bool

Load 从addr对应的文件中重新载入json配置

func (*TJsonTool) Save

func (t *TJsonTool) Save() bool

Save 序列化数据结构到文件

func (*TJsonTool) SaveOther

func (t *TJsonTool) SaveOther(addr string) bool

SaveOther 序列化数据结构到某个文件

type TomlTool

type TomlTool struct{}

func (*TomlTool) Read

func (*TomlTool) Read(addr string, pData interface{}) error

func (*TomlTool) Write

func (*TomlTool) Write(addr string, pData interface{}) error

Jump to

Keyboard shortcuts

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