gobase

package module
v0.0.0-...-9fceb56 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 32 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
)
View Source
var (
	InvalidDBHandle = errors.New("invalid handle")
)

Functions

func AbbreviateArray

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

func AssertHere

func AssertHere(a ...interface{})

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 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 SQLite

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

func (*SQLite) Begin

func (db *SQLite) Begin() (*SQLiteTX, error)

func (*SQLite) Close

func (db *SQLite) Close() error

func (*SQLite) Exec

func (db *SQLite) Exec(query string, args ...interface{}) (int64, int64, error)

func (*SQLite) GetTableRowCount

func (db *SQLite) GetTableRowCount(table string) (int64, error)

func (*SQLite) ListTables

func (db *SQLite) ListTables() ([]string, error)

func (*SQLite) Open

func (db *SQLite) Open(dbName string) error

func (*SQLite) Query

func (db *SQLite) Query(handle ScanHandle, query string, args ...interface{}) error

type SQLiteTX

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

func (*SQLiteTX) Commit

func (db *SQLiteTX) Commit() error

func (*SQLiteTX) Exec

func (db *SQLiteTX) Exec(query string, args ...interface{}) (int64, int64, error)

func (*SQLiteTX) Query

func (db *SQLiteTX) Query(handle ScanHandle, query string, args ...interface{}) error

func (*SQLiteTX) Rollback

func (db *SQLiteTX) Rollback() error

type ScanHandle

type ScanHandle func(rows *sql.Rows) 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 Set

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

func NewSet

func NewSet() *Set

func (*Set) AsStringArray

func (s *Set) AsStringArray() []string

func (*Set) Erase

func (s *Set) Erase(v interface{})

func (*Set) Exist

func (s *Set) Exist(v interface{}) bool

func (*Set) Insert

func (s *Set) Insert(v interface{}) bool

func (*Set) Traversal

func (s *Set) Traversal(call func(v interface{}) error)

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