gobase

package module
v0.0.0-...-24626fc Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: BSD-3-Clause Imports: 30 Imported by: 3

README

gobase

Common utilities library

Documentation

Index

Constants

View Source
const (
	DateTimeFormat = "2006-01-02 15:04:05"
	TimeFormat     = "15:04:05"
	DateFormat     = "2006-01-02"
)

Variables

View Source
var (
	CurCaller         = 1
	DefaultSkipCaller = 2
	DefaultMaxCaller  = 15
)

Functions

func AbbreviateArray

func AbbreviateArray[T any](arr []T) string

func AssertHere

func AssertHere(a ...interface{})

func Combinations

func Combinations[T any](arr []T, m int) [][]T

func CompressJson

func CompressJson(js string) (string, error)

func ContainsInt64

func ContainsInt64(array []int64, val int64) int

func ContainsInterface

func ContainsInterface(array []interface{}, val interface{}) int

func ContainsString

func ContainsString(array []string, val string) int

func ConvertSlice

func ConvertSlice[T any, R any](s []T, f func(T) R) []R

func CopyField

func CopyField(dst any, src any, fields ...string)

func CutUTF8

func CutUTF8(str string, start int, end int, suffix string) string

func Exit

func Exit()

func False

func False(cond bool, a ...interface{})

func FalseF

func FalseF(cond bool, format string, a ...interface{})

func FormatDate

func FormatDate() string

func FormatDateTime

func FormatDateTime() string

func FormatTime

func FormatTime() string

func FormatTimeStamp

func FormatTimeStamp(ts int64) string

func FormatTimeStampMilliWithFormat

func FormatTimeStampMilliWithFormat(ts int64, format string) string

func FormatTimeStampWithFormat

func FormatTimeStampWithFormat(ts int64, format string) string

func GetCPUUsage

func GetCPUUsage() float64

func GetDiskPartitionUsedPercent

func GetDiskPartitionUsedPercent() map[string]float64

func GetDiskPartitions

func GetDiskPartitions() []string

func GetFileInfoOfCaller

func GetFileInfoOfCaller(skip int) (string, string, int)

func GetFullNameOfPointer

func GetFullNameOfPointer(i any) string

func GetLocalIP

func GetLocalIP() (string, error)

func GetMEMUsage

func GetMEMUsage() float64

func GetNotNil

func GetNotNil[T comparable](s ...T) T

func GetShortFuncName

func GetShortFuncName(long string) string

func GetShortNameOfPointer

func GetShortNameOfPointer(i any) string

func GetUpTime

func GetUpTime() uint64

func GetWebPageTitle

func GetWebPageTitle(url string) (string, error)

func IsProcessAlive

func IsProcessAlive(pid int) bool

func ParseTimestamp

func ParseTimestamp(timestamp string) (time.Time, error)

func PathExists

func PathExists(path string) (bool, error)

func PrettyPrintJson

func PrettyPrintJson(js string, indent string) (string, error)

func ReadLine

func ReadLine(filename string, handle func(string) error) error

func RegisterAtExit

func RegisterAtExit(handler func())

func RemoveAnyFromSlice

func RemoveAnyFromSlice(src []interface{}, elem interface{}) []interface{}

func RemoveItemFromSlice

func RemoveItemFromSlice[T comparable](src []T, elem T) []T

func SetChildrenProcessDetached

func SetChildrenProcessDetached(c *exec.Cmd)

func SetChildrenProcessGroupID

func SetChildrenProcessGroupID(c *exec.Cmd)

func SplitAndTrimSpace

func SplitAndTrimSpace(s string, sep string) []string

func True

func True(cond bool, a ...interface{})

func TrueF

func TrueF(cond bool, format string, a ...interface{})

func WriteFile

func WriteFile(filename string, data []byte, perm fs.FileMode) error

Types

type CallFrame

type CallFrame struct {
	Line     int
	Function string
	File     string
}

func GetCallerFrames

func GetCallerFrames(max int, skip int, fullPath bool) []CallFrame

type Map

type Map[T constraints.Ordered, V any] struct {
	Key   T
	Value V
}

type MapSlice

type MapSlice[T constraints.Ordered, V any] []Map[T, V]

func SortMap

func SortMap[T constraints.Ordered, V any](m map[T]V) MapSlice[T, V]

type Queue

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

func NewQueue

func NewQueue() *Queue

func (*Queue) Back

func (q *Queue) Back() interface{}

func (*Queue) Front

func (q *Queue) Front() interface{}

func (*Queue) PopFront

func (q *Queue) PopFront() interface{}

func (*Queue) PushBack

func (q *Queue) PushBack(item interface{})

func (*Queue) SetCapacity

func (q *Queue) SetCapacity(cap int)

func (*Queue) Size

func (q *Queue) Size() int

func (*Queue) Traversal

func (q *Queue) Traversal(handle QueueTraversalHandle)

type QueueTraversalHandle

type QueueTraversalHandle func(interface{}) error

type ScheJob

type ScheJob interface {
	Run()
}

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}
var GlobalScheduler *Scheduler

func NewScheduler

func NewScheduler() *Scheduler

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(name string, spec string, cmd ScheJob) error

func (*Scheduler) DelJob

func (s *Scheduler) DelJob(name string)

func (*Scheduler) Start

func (s *Scheduler) Start()

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type SignalHandler

type SignalHandler func(sig os.Signal)

type SignalSet

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

func NewSignalSet

func NewSignalSet() *SignalSet

func (*SignalSet) Register

func (s *SignalSet) Register(sig os.Signal, handler SignalHandler)

type TableModel

type TableModel struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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