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鉴权、权限管理、动态路由、显隐可控组件、分页封装、多点登录拦截、资源权限、上传下载、代码生成器【可AI辅助】、表单生成器和可配置的导入导出等开发必备功能。 -
excelize
Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets -
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. -
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report. -
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. -
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 -
boilr
:zap: boilerplate template manager that generates files or directories from template repositories -
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.
InfluxDB - Purpose built for real-time analytics at any 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