ctool

package module
v1.2.0 Latest Latest
Warning

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

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

README

Debug

import _ "net/http/pprof"

go func() {
    http.ListenAndServe("0.0.0.0:8897", nil)
}()

go tool pprof http://localhost:8897/debug/pprof/heap

采样 go tool pprof -seconds=10 -http=:9981 http://localhost:8897/debug/pprof/heap

Documentation

Index

Constants

View Source
const (
	YYYY                   = "2006"
	YYYY_MM                = "2006-01"
	YYYY_MM_DD             = "2006-01-02"
	YYYY_MM_DD_HH          = "2006-01-02 15"
	YYYY_MM_DD_HH_MM       = "2006-01-02 15:04"
	YYYY_MM_DD_HH_MM_SS    = "2006-01-02 15:04:05"
	YYYY_MM_DD_HH_MM_SS_MS = "2006-01-02 15:04:05.000"
	HH_MM_SS               = "15:04:05"
	HH_MM_SS_MS            = "15:04:05.000"
)
View Source
const (
	SUCCESS = 0
	FAILED  = 1
)

Variables

This section is empty.

Functions

func BuildFormat added in v1.0.1

func BuildFormat(info HelpInfo) string

BuildFormat

func CheckIfError added in v1.0.1

func CheckIfError(err error)

CheckIfError assert err is nil

func CopyObj added in v1.1.0

func CopyObj[T any, R any](src T) *R

func CopyStream added in v1.1.0

func CopyStream(src io.ReadCloser) ([]byte, io.ReadCloser)

func GetInternalIP added in v1.0.1

func GetInternalIP() string

func Home added in v1.0.1

func Home() (string, error)

Home eg: /home/test

func IsFileExist

func IsFileExist(path string) bool

IsFileExist relative or absolute path

func IsNil added in v1.1.6

func IsNil(vo interface{}) bool

func OpenBrowser added in v1.0.1

func OpenBrowser(url string) error

func PostJson added in v1.0.8

func PostJson(url string, value interface{}) ([]byte, error)

func PostJsons added in v1.0.8

func PostJsons(url string, value []byte) ([]byte, error)

func PrintParams added in v1.0.1

func PrintParams(format string, flagColor Color, params []ParamVO)

PrintParams

func PrintTitle added in v1.0.1

func PrintTitle(command string, helpInfo HelpInfo)

PrintTitle

func PrintWithColorful added in v1.0.1

func PrintWithColorful()

PrintWithColorful

func RandomAlNum added in v1.1.1

func RandomAlNum(length int) string

func RandomAlNumValid added in v1.1.1

func RandomAlNumValid(length int) string

RandomAlNumValid 生成非数字开头的字符串,数据库等地方使用

func RandomAlpha added in v1.1.1

func RandomAlpha(length int) string

func ReadCsvLines

func ReadCsvLines(filename string) [][]string

func ReadLines

func ReadLines[T any](filename string, filterFunc func(string) bool, mapFunc func(string) T) []T

ReadLines filter and map

func ReadLinesNoFilter

func ReadLinesNoFilter[T any](filename string, mapFunc func(string) T) []T

ReadLinesNoFilter only map

func ReadStrLines

func ReadStrLines(filename string, filterFunc func(string) bool) []string

func ReadStrLinesNoFilter

func ReadStrLinesNoFilter(filename string) []string

func ReadTsvLines

func ReadTsvLines(filename string) [][]string

func ToJSONBuffer added in v1.1.0

func ToJSONBuffer(val any) *bytes.Buffer

avoid & => \u0026

func Unpack added in v1.1.7

func Unpack(req *http.Request, ptr interface{}) error

Unpack populates the fields of the struct pointed to by ptr from the HTTP request parameters in req.

Types

type ArrayFlags added in v1.0.1

type ArrayFlags []string

func (*ArrayFlags) Set added in v1.0.1

func (i *ArrayFlags) Set(value string) error

Set 方法是flag.Value接口, 设置flag Value的方法. 通过多个flag指定的值, 所以我们追加到最终的数组上.

func (*ArrayFlags) String added in v1.0.1

func (i *ArrayFlags) String() string

Value ...

type BufferWriter

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

func NewWriter

func NewWriter(filePath string, truncate bool) (*BufferWriter, error)

func NewWriterIgnoreError

func NewWriterIgnoreError(filePath string, truncate bool) *BufferWriter

func (*BufferWriter) Close

func (w *BufferWriter) Close()

func (*BufferWriter) Write

func (w *BufferWriter) Write(val []byte) (nn int, err error)

func (*BufferWriter) WriteLine

func (w *BufferWriter) WriteLine(val string) (nn int, err error)

func (*BufferWriter) WriteString

func (w *BufferWriter) WriteString(val string) (nn int, err error)

type Cache added in v1.0.4

type Cache[T any] interface {
	Get(string) T
	Save(string, T)
	MaxSize() int
	Size() int
}

type Color added in v1.0.1

type Color string
const (
	Red         Color = "\033[0;31m"
	Green       Color = "\033[0;32m"
	Yellow      Color = "\033[0;33m"
	Blue        Color = "\033[0;34m"
	Purple      Color = "\033[0;35m"
	Cyan        Color = "\033[0;36m"
	White       Color = "\033[0;37m"
	LightRed    Color = "\033[0;91m"
	LightGreen  Color = "\033[0;92m"
	LightYellow Color = "\033[0;93m"
	LightBlue   Color = "\033[0;94m"
	LightPurple Color = "\033[0;95m"
	LightCyan   Color = "\033[0;96m"
	LightWhite  Color = "\033[0;97m"
	End         Color = "\033[0m"
)

func (Color) Print added in v1.0.1

func (t Color) Print(content interface{}) string

Print content with color

func (Color) PrintNoEnd added in v1.0.1

func (t Color) PrintNoEnd(content interface{}) string

Print content with color no end

func (Color) Printf added in v1.0.1

func (t Color) Printf(format string, a ...interface{}) string

Printf content with color and format

func (Color) Println added in v1.0.1

func (t Color) Println(content interface{}) string

Print content with color

func (Color) String added in v1.0.1

func (t Color) String() string

type DoublyLinkedList added in v1.0.4

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

func NewDoublyLinkedList added in v1.0.4

func NewDoublyLinkedList[T any](head, tail *DoublyLinkedNode[T]) *DoublyLinkedList[T]

func NewEmptyDoublyLinkedList added in v1.0.4

func NewEmptyDoublyLinkedList[T any]() *DoublyLinkedList[T]

func (*DoublyLinkedList[T]) Add added in v1.0.4

func (list *DoublyLinkedList[T]) Add(data T)

Add to tail

func (*DoublyLinkedList[T]) AddToHead added in v1.0.4

func (list *DoublyLinkedList[T]) AddToHead(data T)

func (*DoublyLinkedList[T]) Clear added in v1.0.4

func (list *DoublyLinkedList[T]) Clear()

func (*DoublyLinkedList[T]) Find added in v1.0.4

func (list *DoublyLinkedList[T]) Find(data T) *DoublyLinkedNode[T]

func (*DoublyLinkedList[T]) IsEmpty added in v1.0.4

func (list *DoublyLinkedList[T]) IsEmpty() bool

func (*DoublyLinkedList[T]) PrintList added in v1.0.4

func (list *DoublyLinkedList[T]) PrintList()

func (*DoublyLinkedList[T]) PrintListWithDetail added in v1.0.4

func (list *DoublyLinkedList[T]) PrintListWithDetail(needDetail bool)

func (*DoublyLinkedList[T]) Remove added in v1.0.4

func (list *DoublyLinkedList[T]) Remove(data T)

func (*DoublyLinkedList[T]) RemoveNode added in v1.0.4

func (list *DoublyLinkedList[T]) RemoveNode(node *DoublyLinkedNode[T])

func (*DoublyLinkedList[T]) RemoveTail added in v1.0.4

func (list *DoublyLinkedList[T]) RemoveTail()

func (*DoublyLinkedList[T]) ReverseBySingle added in v1.0.4

func (list *DoublyLinkedList[T]) ReverseBySingle() *DoublyLinkedList[T]

单链表反转 三个指针前进

type DoublyLinkedNode added in v1.0.4

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

func NewDoublyLinkedNode added in v1.0.4

func NewDoublyLinkedNode[T any](pre, next *DoublyLinkedNode[T], data T) *DoublyLinkedNode[T]

func NewEmptyDoublyLinkedNode added in v1.0.4

func NewEmptyDoublyLinkedNode[T any](data T) *DoublyLinkedNode[T]

type Entry added in v1.0.4

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

type Float added in v1.2.0

type Float interface {
	~float32 | ~float64
}

type HelpInfo added in v1.0.1

type HelpInfo struct {
	Version       string
	BuildVersion  string // from go build command eg: go install -ldflags "-X main.buildVersion=1.0.2"
	Description   string
	SingleFlagLen int
	DoubleFlagLen int
	ValueLen      int
	Flags         []ParamVO
	Options       []ParamVO
	Args          []ParamVO
}

func (HelpInfo) Parse added in v1.0.1

func (helpInfo HelpInfo) Parse()

func (HelpInfo) PrintHelp added in v1.0.1

func (helpInfo HelpInfo) PrintHelp()

PrintHelp info msg

type Integer added in v1.2.0

type Integer interface {
	Signed | Unsigned
}

type LRUCache added in v1.0.4

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

func NewLRUCache added in v1.0.4

func NewLRUCache[T any](maxSize int) *LRUCache[T]

func (*LRUCache[T]) Get added in v1.0.4

func (L *LRUCache[T]) Get(key string) (t T)

func (*LRUCache[T]) MaxSize added in v1.0.4

func (L *LRUCache[T]) MaxSize() int

func (*LRUCache[T]) Save added in v1.0.4

func (L *LRUCache[T]) Save(key string, val T)

func (*LRUCache[T]) Size added in v1.0.4

func (L *LRUCache[T]) Size() int

type Map added in v1.0.8

type Map[K, V comparable] struct {
	// contains filtered or unexported fields
}

func NewMap added in v1.0.8

func NewMap[K, V comparable](k ...MapEntry[K, V]) *Map[K, V]

func (*Map[K, V]) Contain added in v1.0.8

func (m *Map[K, V]) Contain(k K) bool

func (*Map[K, V]) Get added in v1.0.8

func (m *Map[K, V]) Get(k K) V

type MapEntry added in v1.0.8

type MapEntry[K, V comparable] struct {
	Key K
	Val V
}

func NewSortMap added in v1.1.9

func NewSortMap[K comparable, V constraints.Ordered](origin map[K]V) []MapEntry[K, V]

type Maps added in v1.0.8

type Maps[K, V comparable] struct {
	// contains filtered or unexported fields
}

func NewMaps added in v1.0.8

func NewMaps[K, V comparable](k ...MapsEntry[K, V]) *Maps[K, V]

func (*Maps[K, V]) Contain added in v1.0.8

func (m *Maps[K, V]) Contain(k K) bool

func (*Maps[K, V]) Get added in v1.0.8

func (m *Maps[K, V]) Get(k K) []V

func (*Maps[K, V]) Put added in v1.0.8

func (m *Maps[K, V]) Put(k K, v ...V) bool

type MapsEntry added in v1.0.8

type MapsEntry[K, V comparable] struct {
	Key K
	Val []V
}

type Number added in v1.2.0

type Number interface {
	Integer | Float
}

type Ordered added in v1.2.0

type Ordered interface {
	Integer | Float | ~string
}

Ordered 代表所有可比大小排序的类型

type PageVO added in v1.1.9

type PageVO[T any] struct {
	Total int `json:"total"`
	Page  int `json:"page"`
	Data  []T `json:"data"`
}

type ParamInfo added in v1.0.1

type ParamInfo struct {
	Verb    string
	Param   string
	Comment string
	Handler func(params []string)
}

type ParamVO added in v1.0.1

type ParamVO struct {
	Short   string
	Long    string
	Value   string
	Comment string

	Bool    bool
	BoolVar *bool

	Float64    float64
	Float64Var *float64

	IntVar *int
	Int    int

	Int64    int64
	Int64Var *int64

	String    string
	StringVar *string

	Uint    uint
	UintVar *uint
}

type PeriodRateLimiter added in v1.0.6

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

func NewLimiter added in v1.0.6

func NewLimiter(slideWindow time.Duration, maxCount int) *PeriodRateLimiter

func NewMinuteLimiter added in v1.0.6

func NewMinuteLimiter(maxCount int) *PeriodRateLimiter

NewMinuteLimiter 限流: maxCount/min

func NewSecondLimiter added in v1.0.6

func NewSecondLimiter(maxCount int) *PeriodRateLimiter

NewSecondLimiter 限流:maxCount/s

func (*PeriodRateLimiter) Acquire added in v1.0.7

func (l *PeriodRateLimiter) Acquire() bool

func (*PeriodRateLimiter) CalculateCount added in v1.0.7

func (l *PeriodRateLimiter) CalculateCount()

calculateCount 移除 滑动窗口外的元素

简单压测可发现 队列重整理耗时很小

func (*PeriodRateLimiter) QueueState added in v1.0.7

func (l *PeriodRateLimiter) QueueState() int

type Queue added in v1.0.6

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

func (*Queue[T]) IsEmpty added in v1.0.6

func (e *Queue[T]) IsEmpty() bool

func (*Queue[T]) Len added in v1.0.6

func (e *Queue[T]) Len() int

func (*Queue[T]) Peek added in v1.0.6

func (e *Queue[T]) Peek() (t T)

func (*Queue[T]) Pop added in v1.0.6

func (e *Queue[T]) Pop() (t T)

func (*Queue[T]) Push added in v1.0.6

func (e *Queue[T]) Push(ele T)

type ResultVO added in v1.0.2

type ResultVO[T any] struct {
	Data T      `json:"data"`
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func Fail added in v1.0.4

func Fail[T any](code int, msg string) ResultVO[T]

func Failed added in v1.0.2

func Failed[T any]() ResultVO[T]

func FailedWithMsg added in v1.0.2

func FailedWithMsg[T any](msg string) ResultVO[T]

func Success added in v1.0.2

func Success[T any]() ResultVO[T]

func SuccessWith added in v1.0.2

func SuccessWith[T any](data T) ResultVO[T]

func (ResultVO[any]) IsFailed added in v1.0.2

func (result ResultVO[any]) IsFailed() bool

func (ResultVO[any]) IsSuccess added in v1.0.2

func (result ResultVO[any]) IsSuccess() bool

func (ResultVO[any]) JSON added in v1.0.3

func (result ResultVO[any]) JSON() []byte

func (ResultVO[any]) JSONStr added in v1.0.3

func (result ResultVO[any]) JSONStr() string

type Set

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

func NewSet

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

func (*Set[T]) Add

func (s *Set[T]) Add(val ...T)

func (*Set[T]) Adds

func (s *Set[T]) Adds(set *Set[T])

func (*Set[T]) Clear

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

func (*Set[T]) Contains

func (s *Set[T]) Contains(val T) bool

func (*Set[T]) Difference

func (s *Set[T]) Difference(set *Set[T]) *Set[T]

Difference 差集: 在当前集合 但是 不在参数集合内

func (*Set[T]) Intersect

func (s *Set[T]) Intersect(set *Set[T]) *Set[T]

Intersect 交集

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

func (*Set[T]) Join added in v1.1.5

func (s *Set[T]) Join(str string) string

func (*Set[T]) Len

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

func (*Set[T]) Loop

func (s *Set[T]) Loop(action func(T))

func (*Set[T]) Remove

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

func (*Set[T]) Supplementary

func (s *Set[T]) Supplementary(set *Set[T]) *Set[T]

Supplementary 补集 余集

func (*Set[T]) Union

func (s *Set[T]) Union(set *Set[T]) *Set[T]

Union 并集

type Signed added in v1.2.0

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type StopWatch added in v1.0.9

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

StopWatch inspire by spring stopwatch

func NewStopWatch added in v1.0.9

func NewStopWatch() *StopWatch

func NewStopWatchWithName added in v1.0.9

func NewStopWatchWithName(name string) *StopWatch

func (StopWatch) GetTaskCount added in v1.0.9

func (s StopWatch) GetTaskCount() int

func (StopWatch) GetTotalDuration added in v1.0.9

func (s StopWatch) GetTotalDuration() time.Duration

func (StopWatch) PrettyPrint added in v1.0.9

func (s StopWatch) PrettyPrint() string

func (*StopWatch) Run added in v1.1.9

func (s *StopWatch) Run(name string, action func())

func (*StopWatch) Start added in v1.0.9

func (s *StopWatch) Start(name string)

func (*StopWatch) StartAnon added in v1.0.9

func (s *StopWatch) StartAnon()

func (*StopWatch) Stop added in v1.0.9

func (s *StopWatch) Stop()

type TaskInfo added in v1.0.9

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

type Unsigned added in v1.2.0

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Value added in v1.0.1

type Value interface {
	String() string
	Set(string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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