context.Context helpers to make your life slightly easier.
-- import "github.com/gopuff/morecontext"
func ForSignals(sigs ...os.Signal) context.ContextForSignals returns a context.Context that will be cancelled if the given signals (or SIGTERM and SIGINT by default, if none are passed) are received by the process.
func WithMessage(ctx context.Context, format string, args ...interface{}) context.ContextWithMessage is a helper for creating a MessageContext instance, with more context about exactly which context cancellation occurred.
type MessageContext struct {
context.Context
Message string
}MessageContext is a context.Context wrapper that is intended to include some extra metadata about which context was cancelled. Useful for distinguishing e.g. http request cancellation vs deadline vs process sigterm handling.
func (c MessageContext) Err() errorErr returns an error with extra context messaging
type MessageError struct {
Message string
Original error
}MessageError implements error but separates the message from the original error in case you want it.
func (c *MessageError) Error() stringError implements error and prints out the message plus the metadata about which context was cancelled.
func (c *MessageError) Unwrap() errorUnwrap supports errors.Is/errors.As