ctxutil alternatives and similar packages
Based on the "Utilities" category.
Alternatively, view ctxutil alternatives based on common mentions on social networks and blogs.
-
项目文档
基于vite+vue3+gin搭建的开发基础平台(支持TS,JS混用),集成jwt鉴权,权限管理,动态路由,显隐可控组件,分页封装,多点登录拦截,资源权限,上传下载,代码生成器,表单生成器,chatGPT自动查表等开发必备功能。 -
excelize
Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets -
godotenv
A Go port of Ruby's dotenv library (Loads environment variables from .env files) -
Kopia
Cross-platform backup tool for Windows, macOS & Linux with fast, incremental backups, client-side end-to-end encryption, compression and data deduplication. CLI and GUI included. -
go-funk
A modern Go utility library which provides helpers (map, find, contains, filter, ...) -
hystrix-go
Netflix's Hystrix latency and fault tolerance library, for Go -
lancet
A comprehensive, efficient, and reusable util function library of Go. -
gorequest
GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent ) -
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report. -
gojson
Automatically generate Go (golang) struct definitions from example JSON -
create-go-app
✨ A complete and self-contained solution for developers of any qualification to create a production-ready project with backend (Go), frontend (JavaScript, TypeScript) and deploy automation (Ansible, Docker) by running only one CLI command. -
spinner
Go (golang) package with 90 configurable terminal spinner/progress indicators. -
EaseProbe
A simple, standalone, and lightweight tool that can do health/status checking, written in Go. -
filetype
Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature -
mole
CLI application to create ssh tunnels focused on resiliency and user experience. -
boilr
:zap: boilerplate template manager that generates files or directories from template repositories -
mimetype
A fast Golang library for media type and file extension detection, based on magic numbers -
beaver
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps. -
go-underscore
Helpfully Functional Go - A useful collection of Go utilities. Designed for programmer happiness. -
JobRunner
Framework for performing work asynchronously, outside of the request flow -
git-time-metric
Simple, seamless, lightweight time tracking for Git
InfluxDB - Power Real-Time Data Analytics at Scale
Do you think we are missing an alternative of ctxutil or a related project?
Popular Comparisons
README
ctxutil
Package ctxutil is a collection of functions for contexts.
Functions
func Interrupt
func Interrupt() context.Context
Interrupt is a convenience function for catching SIGINT on a background context.
Example:
func main() {
ctx := ctxutil.Interrupt()
// use ctx...
}
func WithSignal
func WithSignal(parent context.Context, sigWhiteList ...os.Signal) context.Context
WithSignal returns a context which is done when an OS signal is sent. parent is a parent context to wrap. sigWhiteList is a list of signals to listen on. According to the signal.Notify behavior, an empty list will listen to any OS signal. If an OS signal closed this context, ErrSignal will be returned in the Err() method of the returned context.
This method creates the signal channel and invokes a goroutine.
Example
func main() {
// Create a context which will be cancelled on SIGINT.
ctx := ctxutil.WithSignal(context.Background(), os.Interrupt)
// use ctx...
}
func WithValues
func WithValues(ctx, values context.Context) context.Context
WithValues composes values from multiple contexts.
It returns a context that exposes the deadline and cancel of ctx
,
and combined values from ctx
and values
.
A value in ctx
context overrides a value with the same key in values
context.
Consider the following standard HTTP Go server stack:
- Middlewares that extract user credentials and request id from the
headers and inject them to the `http.Request` context as values.
- The
http.Handler
launches an asynchronous goroutine task which
needs those values from the context.
- After launching the asynchronous task the handler returns 202 to
the client, the goroutine continues to run in background.
Problem Statement:
- The async task can't use the request context - it is cancelled
as the `http.Handler` returns.
- There is no way to use the context values in the async task.
- Specially if those values are used automatically with client
`http.Roundtripper` (extract the request id from the context
and inject it to http headers in a following request.)
The suggested function ctx := ctxutil.WithValues(ctx, values)
does the following:
- When
ctx.Value()
is called, the key is searched in the
original `ctx` and if not found it searches in `values`.
- When
Done()
/Deadline()
/Err()
are called, it is uses
original `ctx`'s state.
Example
This is how an http.Handler
should run a goroutine that need
values from the context.
func handle(w http.ResponseWriter, r *http.Request) {
// [ do something ... ]
// Create async task context that enables it run for 1 minute, for example
asyncCtx, asyncCancel = ctxutil.WithTimeout(context.Background(), time.Minute)
// Use values from the request context
asyncCtx = ctxutil.WithValues(asyncCtx, r.Context())
// Run the async task with it's context
go func() {
defer asyncCancel()
asyncTask(asyncCtx)
}()
}
Created by goreadme