[go: up one dir, main page]

Skip to content

searKing/golang

Repository files navigation

Go Reference Report card

golang

various libs or tools for Golang

GoLibraries

  • expexp holds experimental packages and defines various functions useful with generics of any type.
    • slices defines various functions useful with slices of any type.
    • maps defines various functions useful with maps of any type.
    • image defines Point[T] and Rectangle[T] of any type.
    • sync.LRU implements a thread safe fixed size LRU cache, based on not-thread safe lru
    • sync.FixedPool is a set of resident and temporary items that may be individually saved and retrieved.
    • types.Optional represents a Value that may be null.
    • container.hashring — hashring provides a consistent hashing function, read more about consistent hashing on wikipedia: Consistent_hashing.
    • container.lru implements a Go map[K]V but implements a non-thread safe fixed size LRU cache. Loads, stores, and deletes run in amortized constant time.
    • container.queue implements a two-stage queue of FIFO, not a deque.
  • slog - slog provides GlogHandler, GlogHumanHandler, NewRotateHandler and MultiHandler handlers for slog
  • webhdfs - Hadoop WebHDFS REST API client library for Golang with fs module like (asynchronous) interface.
  • Thread — Thread should be used for such as calling OS services or non-Go library functions that depend on per-thread state, as runtime.LockOSThread().
  • BurstLimiter — BurstLimiter behaves like Limiter in time, BurstLimiter controls how frequently events are allowed to happen.
    • It implements a "token bucket" of size b, initially full、empty or any size, and refilled by PutToken or PutTokenN. The difference is that time/rate.Limiterinitially full and refilled at rate r tokens per second.
    • It implements a Reorder Buffer allocated by Reserve or ReserveN into account when allowing future events and Wait or WaitN blocks until lim permits n events to happen.
  • generator — Generator behaves like Generator in python or ES6, with yield and next statements.
  • signal — Signal enhances signal.Notify with the stacktrace of cgo.
  • sql — Enhance go std sql.
    • NullDuration

      NullDuration represents an interface that may be null. NullDuration implements the Scanner interface so it can be used as a scan destination, similar to sql.NullString.
    • NullJson

      NullJson represents an interface that may be null. NullJson implements the Scanner interface so it can be used as a scan destination, similar to sql.NullString. Deprecate, use go-nulljson instead. For more information, see: https://pkg.go.dev/github.com/searKing/golang/tools/go-nulljson
  • ternary_search_tree — A type of trie (sometimes called a prefix tree) where nodes are arranged in a manner similar to a binary search tree, but with up to three children rather than the binary tree's limit of two.
  • mux — Mux is a generic Go library to multiplex connections based on their payload. Using mux, you can serve gRPC, SSH, HTTPS, HTTP, Go RPC, and pretty much any other protocol on the same TCP listener.
  • SniffReader — A Reader that allows sniff and read from the provided input reader. data is buffered if Sniff(true) is called. buffered data is taken first, if Sniff(false) is called.
  • multiple_prefix - Prefixes for decimal and binary multiples, Prefixes for decimal multiples , Prefixes for binary multiples.
  • flag — Enhance go std flag, such as StringSlice that is a flag.Value that accumulates strings, e.g. --flag=one --flag=two would produce []string{"one", "two"}.
  • goroutine — goroutine is a collection of apis about goroutine.
    • ID() — returns goroutine id of the goroutine that calls it.
    • Lock — represents a goroutine ID, with goroutine ID checked, that is whether GoRoutines of lock newer and check caller differ.
  • hashring — hashring provides a consistent hashing function, read more about consistent hashing on wikipedia: Consistent_hashing.
  • RotateFile — RotateFile derived from os.File, and is designed to ease administration of systems that generate large numbers of files. It allows automatic rotation, removal, and handler of files. Each file may be handled daily, weekly, monthly, strftimely, time_layoutly or when it grows too large.
    • NewFactoryFromFile — NewFactoryFromFile is an example of os.RotateFile register for logrus.
  • CacheFile - CacheFile is a package cache(Eventual consistency, behaves like sync.LRU[string, *os.File]), backed by a file system directory tree. It is safe for multiple processes on a single machine to use the same cache directory in a local file system simultaneously. They will coordinate using operating system file locks and may duplicate effort but will not corrupt the cache. It's usually used to support download cache, download if cache file not hit.
  • UnlinkOldestFiles - UnlinkOldestFiles unlink old files if DiskQuota exceeds. It's usually used for disk clean.

GoGenerateTools

  • go generate is only useful if you have tools to use it with! Here is an incomplete list of useful tools that generate code.
  • go-syncmap — Generates Go code using a package as a generic template for sync.Map.
  • go-syncpool — Generates Go code using a package as a generic template for sync.Pool.
  • go-atomicvalue — Generates Go code using a package as a generic template for atomic.Value.
  • go-option — Generates Go code using a package as a graceful option.
  • go-nulljson — Generates Go code using a package as a generic template that implements sql.Scanner and sql.Valuer.
  • go-enum — Generates Go code using a package as a generic template, which implements interface fmt.Stringer | binary | json | text | sql | yaml for enums.
  • go-import — Performs auto import of non go files.
  • go-sqlx — Generates Go code using a package as a generic template that implements sqlx.