jokode

package module
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MulanPSL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilePermNone        = 0000
	FilePermUserExOnly  = FilePermNone + 0100
	FilePermUserWrOnly  = FilePermNone + 0200
	FilePermUserRdOnly  = FilePermNone + 0400
	FilePermUserRdWr    = FilePermUserRdOnly | FilePermUserWrOnly
	FilePermUserAll     = FilePermUserExOnly | FilePermUserRdWr
	FilePermGroupExOnly = FilePermNone + 0010
	FilePermGroupWrOnly = FilePermNone + 0020
	FilePermGroupRdOnly = FilePermNone + 0040
	FilePermGroupRdWr   = FilePermGroupRdOnly | FilePermGroupWrOnly
	FilePermGroupAll    = FilePermGroupExOnly | FilePermGroupRdWr
	FilePermOtherExOnly = FilePermNone + 0001
	FilePermOtherWrOnly = FilePermNone + 0002
	FilePermOtherRdOnly = FilePermNone + 0004
	FilePermOtherRdWr   = FilePermOtherRdOnly | FilePermOtherWrOnly
	FilePermOtherAll    = FilePermOtherExOnly | FilePermOtherRdWr
	FilePermOsDef       = FilePermUserRdWr | FilePermGroupRdWr | FilePermOtherRdOnly
	FilePermAll         = FilePermUserAll | FilePermGroupAll | FilePermOtherAll
)
View Source
const (
	LogLevelStrDebug = "DEBUG"
	LogLevelStrInfo  = "INFO"
	LogLevelStrWarn  = "WARN"
	LogLevelStrError = "ERROR"
	LogLevelStrFatal = "FATAL"

	LogLevelStrUnknown = "UNKNOWN"
)
View Source
const (
	DefTimeFormatMs = "2006-01-02 15:04:05.000"
	DefTimeFormat   = "2006-01-02 15:04:05"
	DefDateFormat   = "2006-01-02"
)

Variables

View Source
var ZeroTime time.Time

Functions

func AToTime

func AToTime(t string) time.Time

func AddTask

func AddTask()

func AtoF64

func AtoF64(d string) float64

func AtoI

func AtoI(d string) int

func AtoI64

func AtoI64(d string) int64

func BtoI

func BtoI(b bool) int

func CheckFilePathUpward

func CheckFilePathUpward(fileName string) (string, bool)

func CheckFilePathUpwardFrom

func CheckFilePathUpwardFrom(fileName, basePath string) (string, bool)

func DateToA

func DateToA(t time.Time) string

func Debug

func Debug(args ...any)

func Debugf

func Debugf(format string, args ...any)

func Decimal

func Decimal(val float64, pre int) float64

func DirExists

func DirExists(name string) bool

func DirNotExists

func DirNotExists(name string) bool

func Error

func Error(args ...any)

func Errorf

func Errorf(format string, args ...any)

func F64toA

func F64toA(d int64) string

func Fatal

func Fatal(args ...any)

func Fatalf

func Fatalf(format string, args ...any)

func FileExists

func FileExists(name string) bool

func FileNotExists

func FileNotExists(name string) bool

func GetLocalIpByRemoteTcp

func GetLocalIpByRemoteTcp(remoteHost string, remotePort uint64, timeOut time.Duration) (net.IP, error)

func GetProcessName

func GetProcessName() string

func GetUUIDString

func GetUUIDString(id UUID) string

func HttpClientSendReq

func HttpClientSendReq(method string, urlPath string, params url.Values, data []byte, timeOut time.Duration) ([]byte, error)

func HttpGet

func HttpGet(urlPath string, params url.Values, timeOut time.Duration) ([]byte, error)

func HttpPostObject

func HttpPostObject(urlPath string, params url.Values, obj any, timeOut time.Duration) ([]byte, error)

func Info

func Info(args ...any)

func Infof

func Infof(format string, args ...any)

func InitLogger

func InitLogger(cfg *LogConfig) error

func InitLoggerByPath

func InitLoggerByPath(logFilePath string) error

func IsNilObject

func IsNilObject(obj any) bool

func IsNotNilObject

func IsNotNilObject(obj any) bool

func Json2Str

func Json2Str(obj any) string

func LoadJsonObjectFromFile

func LoadJsonObjectFromFile(obj any, filePath string) error

func LogSync

func LogSync() error

func MkdirForFile

func MkdirForFile(filePath string) error

func NewUUIDString

func NewUUIDString() string

func OpenExclusiveFile

func OpenExclusiveFile(filePath string) (*os.File, error)

func OpenFileForAppend

func OpenFileForAppend(filePath string) (*os.File, error)

func OpenFileForRead

func OpenFileForRead(filePath string) (*os.File, error)

func OpenFileForWrite

func OpenFileForWrite(filePath string) (*os.File, error)

func ParseAddr

func ParseAddr(addr string) (host string, port int, err error)

func RegLoggerProvider

func RegLoggerProvider(provider LoggerProvider)

func ResetSnowNode

func ResetSnowNode(node int64)

func SaveJsonObjectToFile

func SaveJsonObjectToFile(obj any, filePath string) error

func SetRunMode

func SetRunMode(mode RunMode)

func SplitFilePath

func SplitFilePath(txt string) (dir, name, ext string)

func Str2Json

func Str2Json(data string, obj any) (ok bool)

func SumMd5Data

func SumMd5Data(data []byte) string

func SumMd5String

func SumMd5String(str string) string

func TaskDone

func TaskDone()

func TimeMsToA

func TimeMsToA(t time.Time) string

func TimeToA

func TimeToA(t time.Time) string

func UUIDEquals

func UUIDEquals(u1, u2 UUID) bool

func WaitForAllTasksDone

func WaitForAllTasksDone()

func Warn

func Warn(args ...any)

func Warnf

func Warnf(format string, args ...any)

func WriteFile

func WriteFile(filePath string, data []byte) error

Types

type AppCmd

type AppCmd struct {
	AppFlagCmdBase
	// contains filtered or unexported fields
}

func NewAppCmd

func NewAppCmd(handler AppCmdHandler, name, usage string) *AppCmd

func (*AppCmd) GetHandler

func (cmd *AppCmd) GetHandler() AppCmdHandler

type AppCmdHandler

type AppCmdHandler func()

type AppFlagBase

type AppFlagBase struct {
	AppFlagCmdBase
	// contains filtered or unexported fields
}

func (*AppFlagBase) Exist

func (af *AppFlagBase) Exist() bool

func (*AppFlagBase) GetLongName

func (af *AppFlagBase) GetLongName() string

func (*AppFlagBase) GetShortName

func (af *AppFlagBase) GetShortName() string

func (*AppFlagBase) Init

func (af *AppFlagBase) Init(shortName, longName, usage string)

type AppFlagBool

type AppFlagBool struct {
	AppFlagBase
}

func NewAppFlagBool

func NewAppFlagBool(shortName, longName, usage string) *AppFlagBool

func (*AppFlagBool) GetBool

func (af *AppFlagBool) GetBool() bool

type AppFlagCmdBase

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

func (*AppFlagCmdBase) GetName

func (af *AppFlagCmdBase) GetName() string

func (*AppFlagCmdBase) GetUsage

func (af *AppFlagCmdBase) GetUsage() string

func (*AppFlagCmdBase) Init

func (af *AppFlagCmdBase) Init(name, usage string)

type AppFlagFloat64

type AppFlagFloat64 struct {
	AppFlagBase
	// contains filtered or unexported fields
}

func NewAppFlagFloat64

func NewAppFlagFloat64(shortName, longName, usage string, defVal float64) *AppFlagFloat64

func (*AppFlagFloat64) GetFloat64

func (af *AppFlagFloat64) GetFloat64() float64

type AppFlagInt

type AppFlagInt struct {
	AppFlagBase
	// contains filtered or unexported fields
}

func NewAppFlagInt

func NewAppFlagInt(shortName, longName, usage string, defVal int) *AppFlagInt

func (*AppFlagInt) GetInt

func (af *AppFlagInt) GetInt() int

type AppFlagInt64

type AppFlagInt64 struct {
	AppFlagBase
	// contains filtered or unexported fields
}

func NewAppFlagInt64

func NewAppFlagInt64(shortName, longName, usage string, defVal int64) *AppFlagInt64

func (*AppFlagInt64) GetInt64

func (af *AppFlagInt64) GetInt64() int64

type AppFlagMgr

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

func NewAppFlagMgr

func NewAppFlagMgr() *AppFlagMgr

func (*AppFlagMgr) RegisterCmd

func (mgr *AppFlagMgr) RegisterCmd(cmd *AppCmd)

func (*AppFlagMgr) RegisterMainCmd

func (mgr *AppFlagMgr) RegisterMainCmd(handler AppCmdHandler)

type AppFlagString

type AppFlagString struct {
	AppFlagBase
	// contains filtered or unexported fields
}

func NewAppFlagString

func NewAppFlagString(shortName, longName, usage string, defVal string) *AppFlagString

func (*AppFlagString) GetString

func (af *AppFlagString) GetString() string

type AppFlagUint

type AppFlagUint struct {
	AppFlagBase
	// contains filtered or unexported fields
}

func NewAppFlagUint

func NewAppFlagUint(shortName, longName, usage string, defVal uint) *AppFlagUint

func (*AppFlagUint) GetUint

func (af *AppFlagUint) GetUint() uint

type EmptyStruct

type EmptyStruct struct {
}

type IAppFlag

type IAppFlag interface {
	GetShortName() string
	GetLongName() string
	GetUsage() string
	Exist() bool
}

type IAppFlagBool

type IAppFlagBool interface {
	IAppFlag
	GetBool() bool
}

type IAppFlagFloat64

type IAppFlagFloat64 interface {
	IAppFlag
	GetFloat64() float64
}

type IAppFlagInt

type IAppFlagInt interface {
	IAppFlag
	GetInt() int
}

type IAppFlagInt64

type IAppFlagInt64 interface {
	IAppFlag
	GetInt64() int64
}

type IAppFlagString

type IAppFlagString interface {
	IAppFlag
	GetString() string
}

type IAppFlagUint

type IAppFlagUint interface {
	IAppFlag
	GetUint() uint
}

type IFixDefaultValue

type IFixDefaultValue interface {
	FixDefaultValue() error
}

type ILocker

type ILocker interface {
	Lock()
	Unlock()
}

type IQueue

type IQueue[T any] interface {
	Empty() bool
	EnQueue(value T)
	DeQueue() (value T, ok bool)
	GetHead() (value T, ok bool)
	GetTail() (value T, ok bool)
	Reset()
	Size() int
}

type IRWLocker added in v0.8.5

type IRWLocker interface {
	ILocker
	RLock()
	RUnlock()
}

type IRunnable

type IRunnable interface {
}

type ITcpAcceptor

type ITcpAcceptor interface {
	Accept(conn *net.TCPConn)
	OnError(err error)
	OnData(data []byte)
}

type InterfaceStructure

type InterfaceStructure struct {
	Pt uintptr
	Pv uintptr
}

func AsInterfaceStructure

func AsInterfaceStructure(obj any) InterfaceStructure

type JoAppStatus

type JoAppStatus int
const (
	JoAppStatusNone JoAppStatus = iota
	JoAppStatusFlagsParsed
)

func (JoAppStatus) String

func (st JoAppStatus) String() string

type JoLogger

type JoLogger interface {
	Debug(args ...any)
	Info(args ...any)
	Warn(args ...any)
	Error(args ...any)
	Fatal(args ...any)
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
	Fatalf(format string, args ...any)
	Sync() error
}

func Logger

func Logger() JoLogger
type LinkList[T any] struct {
	// contains filtered or unexported fields
}
func NewLinkList[T any]() *LinkList[T]

func (*LinkList[T]) Back added in v0.8.5

func (l *LinkList[T]) Back() *ListNode[T]

func (*LinkList[T]) Front added in v0.8.5

func (l *LinkList[T]) Front() *ListNode[T]

func (*LinkList[T]) Init added in v0.8.5

func (l *LinkList[T]) Init() *LinkList[T]

func (*LinkList[T]) InsertAfter added in v0.8.5

func (l *LinkList[T]) InsertAfter(v T, mark *ListNode[T]) *ListNode[T]

func (*LinkList[T]) InsertBefore added in v0.8.5

func (l *LinkList[T]) InsertBefore(v T, mark *ListNode[T]) *ListNode[T]

func (*LinkList[T]) Len added in v0.8.5

func (l *LinkList[T]) Len() int

func (*LinkList[T]) MoveAfter added in v0.8.5

func (l *LinkList[T]) MoveAfter(n, mark *ListNode[T])

func (*LinkList[T]) MoveBefore added in v0.8.5

func (l *LinkList[T]) MoveBefore(n, mark *ListNode[T])

func (*LinkList[T]) MoveToBack added in v0.8.5

func (l *LinkList[T]) MoveToBack(n *ListNode[T])

func (*LinkList[T]) MoveToFront added in v0.8.5

func (l *LinkList[T]) MoveToFront(n *ListNode[T])

func (*LinkList[T]) PushBack added in v0.8.5

func (l *LinkList[T]) PushBack(v T) *ListNode[T]

func (*LinkList[T]) PushBackList added in v0.8.5

func (l *LinkList[T]) PushBackList(lst *LinkList[T])

func (*LinkList[T]) PushBackSlice added in v0.8.5

func (l *LinkList[T]) PushBackSlice(s []T)

func (*LinkList[T]) PushFront added in v0.8.5

func (l *LinkList[T]) PushFront(v T) *ListNode[T]

func (*LinkList[T]) PushFrontList added in v0.8.5

func (l *LinkList[T]) PushFrontList(lst *LinkList[T])

func (*LinkList[T]) Remove added in v0.8.5

func (l *LinkList[T]) Remove(n *ListNode[T]) T

func (*LinkList[T]) ToSlice added in v0.8.5

func (l *LinkList[T]) ToSlice() []T

type ListNode

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

func NewListNode added in v0.8.5

func NewListNode[T any](val T) *ListNode[T]

func (*ListNode[T]) Data added in v0.8.5

func (n *ListNode[T]) Data() T

func (*ListNode[T]) Next

func (n *ListNode[T]) Next() *ListNode[T]

func (*ListNode[T]) Prev added in v0.8.5

func (n *ListNode[T]) Prev() *ListNode[T]

type Locker

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

func NewLocker

func NewLocker() *Locker

func (*Locker) Lock

func (l *Locker) Lock()

func (*Locker) Unlock

func (l *Locker) Unlock()

type LogConfig

type LogConfig struct {
	Level      string `json:"level"`      // 输出的最低日志等级, DEBUG < INFO < WARN < ERROR < FATAL
	FileName   string `json:"fileName"`   // 输出日志文件名
	MaxSize    int    `json:"maxSize"`    // 日志文件的最大大小, 单位 MB, 默认 100 MB
	MaxAge     int    `json:"maxAge"`     // 根据文件名中编码的时间戳保留的旧日志文件的最大天数
	MaxBackups int    `json:"maxBackups"` // 要保留的旧日志文件的最大数量, 默认是保留所有旧的日志文件
	OutToStdIo bool   `json:"outToStdIo"` // 是否输出到控制台, 默认输出
	TraceStack bool   `json:"traceStack"` // 是否输出堆栈信息
}

func FixLogConfigDefValues

func FixLogConfigDefValues(cfg *LogConfig) *LogConfig

func NewLogConfig

func NewLogConfig() *LogConfig

type LogLevel

type LogLevel int
const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal

	LogLevelUnknown = 100
)

func ParseLogLevel

func ParseLogLevel(str string) LogLevel

func (LogLevel) String

func (level LogLevel) String() string

type LoggerProvider

type LoggerProvider interface {
	GetName() string
	InitLogger(cfg *LogConfig) (JoLogger, error)
	GetLogger() JoLogger
}

type NoneLocker

type NoneLocker struct {
}

func (*NoneLocker) Lock

func (*NoneLocker) Lock()

func (*NoneLocker) Unlock

func (*NoneLocker) Unlock()

type NoneLogger

type NoneLogger struct {
}

func (*NoneLogger) Debug

func (l *NoneLogger) Debug(...any)

func (*NoneLogger) Debugf

func (l *NoneLogger) Debugf(string, ...any)

func (*NoneLogger) Error

func (l *NoneLogger) Error(...any)

func (*NoneLogger) Errorf

func (l *NoneLogger) Errorf(string, ...any)

func (*NoneLogger) Fatal

func (l *NoneLogger) Fatal(...any)

func (*NoneLogger) Fatalf

func (l *NoneLogger) Fatalf(format string, args ...any)

func (*NoneLogger) Info

func (l *NoneLogger) Info(...any)

func (*NoneLogger) Infof

func (l *NoneLogger) Infof(string, ...any)

func (*NoneLogger) Sync

func (l *NoneLogger) Sync() error

func (*NoneLogger) Warn

func (l *NoneLogger) Warn(...any)

func (*NoneLogger) Warnf

func (l *NoneLogger) Warnf(string, ...any)

type NoneRWLocker added in v0.8.5

type NoneRWLocker struct {
	NoneLocker
}

func (*NoneRWLocker) RLock added in v0.8.5

func (*NoneRWLocker) RLock()

func (*NoneRWLocker) RUnlock added in v0.8.5

func (*NoneRWLocker) RUnlock()

type Queue

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

func NewSafeQueue added in v0.8.5

func NewSafeQueue[T any]() *Queue[T]

func NewUnsafeQueue added in v0.8.5

func NewUnsafeQueue[T any]() *Queue[T]

func (*Queue[T]) DeQueue added in v0.8.5

func (q *Queue[T]) DeQueue() (v T, ok bool)

func (*Queue[T]) Empty added in v0.8.5

func (q *Queue[T]) Empty() bool

func (*Queue[T]) EnQueue added in v0.8.5

func (q *Queue[T]) EnQueue(value T)

func (*Queue[T]) GetHead added in v0.8.5

func (q *Queue[T]) GetHead() (v T, ok bool)

func (*Queue[T]) GetTail added in v0.8.5

func (q *Queue[T]) GetTail() (v T, ok bool)

func (*Queue[T]) Reset added in v0.8.5

func (q *Queue[T]) Reset()

func (*Queue[T]) Size added in v0.8.5

func (q *Queue[T]) Size() int

type RWLocker

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

func NewRWLocker

func NewRWLocker() *RWLocker

func (*RWLocker) Lock

func (l *RWLocker) Lock()

func (*RWLocker) RLock

func (l *RWLocker) RLock()

func (*RWLocker) RUnlock

func (l *RWLocker) RUnlock()

func (*RWLocker) Unlock

func (l *RWLocker) Unlock()

type RunMode

type RunMode int
const (
	RunModeNone RunMode = iota
	RunModeDev
	RunModeProd
)

func GetRunMode

func GetRunMode() RunMode

func (RunMode) IsUnderDev

func (m RunMode) IsUnderDev() bool

func (RunMode) IsUnderProd

func (m RunMode) IsUnderProd() bool

func (RunMode) String

func (m RunMode) String() string

type Set

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

func NewSet

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

func (*Set[T]) Add

func (s *Set[T]) Add(v T)

func (*Set[T]) Clear

func (s *Set[T]) Clear()

func (*Set[T]) Exist

func (s *Set[T]) Exist(v T) bool

func (*Set[T]) Remove

func (s *Set[T]) Remove(v T)

func (*Set[T]) Size

func (s *Set[T]) Size() int

func (*Set[T]) ToSlice

func (s *Set[T]) ToSlice() []T

type SnowID

type SnowID = snowflake.ID

func NewSnowId

func NewSnowId() SnowID

type StdLogger

type StdLogger struct{}

func (*StdLogger) Debug

func (l *StdLogger) Debug(args ...any)

func (*StdLogger) Debugf

func (l *StdLogger) Debugf(format string, args ...any)

func (*StdLogger) Error

func (l *StdLogger) Error(args ...any)

func (*StdLogger) Errorf

func (l *StdLogger) Errorf(format string, args ...any)

func (*StdLogger) Fatal

func (l *StdLogger) Fatal(args ...any)

func (*StdLogger) Fatalf

func (l *StdLogger) Fatalf(format string, args ...any)

func (*StdLogger) Info

func (l *StdLogger) Info(args ...any)

func (*StdLogger) Infof

func (l *StdLogger) Infof(format string, args ...any)

func (*StdLogger) Sync

func (l *StdLogger) Sync() error

func (*StdLogger) Warn

func (l *StdLogger) Warn(args ...any)

func (*StdLogger) Warnf

func (l *StdLogger) Warnf(format string, args ...any)

type TcpAcceptor

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

func (*TcpAcceptor) Accept

func (a *TcpAcceptor) Accept(conn *net.TCPConn)

type TcpServer

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

func (*TcpServer) Start

func (s *TcpServer) Start(addr string, acceptor ITcpAcceptor) error

func (*TcpServer) Stop

func (s *TcpServer) Stop()

type UUID

type UUID = uuid.UUID

func GetUUIDFromString

func GetUUIDFromString(id string) (UUID, error)

func GetUUIDFromStringMust

func GetUUIDFromStringMust(id string) UUID

func NewUUID

func NewUUID() UUID

type UdpServer

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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