contexts

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UserKey static key for UserObject in context
	UserKey ContextUserKey
	// ParamsKey static key for Query parameters in request
	ParamsKey ContextParamsKey
	// PathKey path string key for context
	PathKey ContextPathKey
	// ArgsKey key for arguments in URL
	ArgsKey ContextArgumentsKey
	// BodyKey key for body in a request
	BodyKey ContextBodyKey
	// RequestIDKey key for request ID
	RequestIDKey ContextRequestIDKey
)

Functions

func GetArgs

func GetArgs(ctx context.Context) (value map[string]string)

GetArgs get the arguments and return as a map[string]string used mainly for url defined parameters like name or id for RESTful APIs

func GetBody

func GetBody(ctx context.Context) interface{}

GetBody gets body from context

func GetParams

func GetParams(ctx context.Context) (params map[string]string)

GetParams gets a param as map[string]string if exists used mainly for url arguments like key=value

func GetPath

func GetPath(ctx context.Context) (path string)

GetPath gets a path argument if any

func GetRequestID

func GetRequestID(ctx context.Context) (requestID string)

GetRequestID get request ID from context

func GetUser

func GetUser(ctx context.Context) (user interface{})

GetUser gets the user from the user key

func New

func New() context.Context

New constructs a new context

func SetArgs

func SetArgs(ctx context.Context, value map[string]string) context.Context

SetArgs set a map to a a args key used mainly for url defined parameters like name or id for RESTful APIs

func SetBody

func SetBody(ctx context.Context, body interface{}) context.Context

SetBody set an interface as the body of the payload

func SetParams

func SetParams(ctx context.Context, value map[string]string) context.Context

SetParams sets a map[string]string to the context used mainly for url arguments like key=value

func SetPath

func SetPath(ctx context.Context, value string) context.Context

SetPath set a string value to be used as a path string to a context

func SetRequestID

func SetRequestID(ctx context.Context, requestID string) context.Context

SetRequestID sets a request ID into context

func SetUser

func SetUser(ctx context.Context, value interface{}) context.Context

SetUser sets a interface{} value to the user key

Types

type ContextArgumentsKey

type ContextArgumentsKey struct{}

ContextArgumentsKey path key

type ContextBodyKey

type ContextBodyKey struct{}

ContextBodyKey path key

type ContextParamsKey

type ContextParamsKey struct{}

ContextParamsKey params key

type ContextPathKey

type ContextPathKey struct{}

ContextPathKey path key

type ContextRequestIDKey

type ContextRequestIDKey struct{}

ContextRequestIDKey request id key

type ContextUserKey

type ContextUserKey struct{}

ContextUserKey user key

Jump to

Keyboard shortcuts

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