ctx

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: MIT Imports: 6 Imported by: 7

README

Build Status

CJToolkit Context System

Just a simple context system for background and user request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearBackgroundContext added in v1.0.2

func ClearBackgroundContext(context BackgroundContext)

Clear Background Context, best used with a defer function after creating the new context.

func SetHealthCheckMaxAttemptOnBackgroundContext added in v1.0.3

func SetHealthCheckMaxAttemptOnBackgroundContext(context BackgroundContext, maxAttempt int)

Set Health Check Max Attempt on Background Context

func SetHealthCheckTimeOutOnBackgroundContext added in v1.0.3

func SetHealthCheckTimeOutOnBackgroundContext(context BackgroundContext, timeout time.Duration)

Set Health Check Time Out on Background Context

Types

type BackgroundContext

type BackgroundContext interface {
	Set(key, value interface{})
	Get(key interface{}) interface{}

	// The fn function only gets called if there is a cache miss. Return error as nil to bypass health check.
	Persist(key interface{}, fn func() (interface{}, error)) interface{}
}

Background Context

func NewBackgroundContext

func NewBackgroundContext() BackgroundContext

Create new background context.

type Context

type Context interface {
	Title() string
	SetTitle(title string)
	Data(key interface{}) interface{}
	SetData(key, value interface{})

	// The fn function only gets called if there is a cache miss.
	PersistData(key interface{}, fn func() interface{}) interface{}

	Ctx() context.Context
	Request() *http.Request
	ResponseWriter() http.ResponseWriter
}

For storing anything related to user request

func GetContext

func GetContext(req *http.Request) Context

Pulls out user context that was saved to the *http.Request.

func NewContext

func NewContext(res http.ResponseWriter, req *http.Request) (*http.Request, Context)

Create new context for user request, also saves context inside *http.Request without disturbing the context of the user request.

func NewContextByContext added in v1.0.6

func NewContextByContext(ctx context.Context) Context

Create new context by context.

Jump to

Keyboard shortcuts

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