util

package
v0.0.0-...-7a6c0c8 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LogLevelInfo    = 1 << 0
	LogLevelError   = LogLevelInfo | (1 << 1)
	LogLevelWarning = LogLevelError | (1 << 2)
	LogLevelDebug   = LogLevelWarning | (1 << 3)
)

LogLevel 日志等级

View Source
var (
	Reset  = "\033[0m"
	Red    = "\033[31m"
	Green  = "\033[32m"
	Yellow = "\033[33m"
	Blue   = "\033[34m"
)

各种颜色

View Source
var Json jsonCoder

Json 使用的解析器 使用字节的sonic库 由于只支持amd64, 所以提供了修改的方法

Functions

func CheckPortAvailable

func CheckPortAvailable(port int) bool

CheckPortAvailable 检查端口是否可用

func GetFormatTime

func GetFormatTime() string

GetFormatTime 获取当前时间的格式化字符串

func GetNanoTimeStamp

func GetNanoTimeStamp() int64

GetNanoTimeStamp 获取当前时间戳 纳秒

func GetTimeStamp

func GetTimeStamp() int64

GetTimeStamp 获取当前时间戳 秒 备用

func GetTimeStampFloat64

func GetTimeStampFloat64() float64

GetTimeStampFloat64 获取当前时间戳

https://12.onebot.dev/connect/data-protocol/event/ 要求的Time为float64

func GetUUID

func GetUUID() string

GetUUID 获取一个随机的UUID

来自github.com/google/uuid

func PrintGoroutineStack

func PrintGoroutineStack()

func SetJsonCoder

func SetJsonCoder(j jsonCoder)

SetJsonCoder 修改Json解析器

func SetLogger

func SetLogger(l LogInterface)

SetLogger 设置日志Logger

Types

type DefaultJson

type DefaultJson struct {
}

func (*DefaultJson) Marshal

func (d *DefaultJson) Marshal(v interface{}) ([]byte, error)

Marshal 默认解析器编码

func (*DefaultJson) Unmarshal

func (d *DefaultJson) Unmarshal(data []byte, v interface{}) error

Unmarshal 默认解析器解码

type Log

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

Log Logger的默认实现

func (*Log) Debug

func (l *Log) Debug(s string)

Debug 打印Debug

func (*Log) Error

func (l *Log) Error(s string)

Error 打印Error

func (*Log) Info

func (l *Log) Info(s string)

Info 打印Info

func (*Log) Println

func (l *Log) Println(s string)

Println 打印

func (*Log) SetLogLevel

func (l *Log) SetLogLevel(level int)

SetLogLevel 修改日志等级

func (*Log) Warning

func (l *Log) Warning(s string)

Warning 打印Warning

type LogInterface

type LogInterface interface {
	Println(string)
	Info(string)
	Warning(string)
	Error(string)
	Debug(string)
	SetLogLevel(int)
}

LogInterface 日志接口

var Logger LogInterface

Logger log的接口

type Ticker

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

Ticker 计时器

func NewTicker

func NewTicker() *Ticker

NewTicker 创建一个计时器

func (*Ticker) GetDuration

func (t *Ticker) GetDuration() int64

GetDuration 获取计时器的时间 纳秒

func (*Ticker) GetDurationString

func (t *Ticker) GetDurationString() string

GetDurationString 获取计时器的时间 字符串 包含单位

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop 停止计时

Jump to

Keyboard shortcuts

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