context

package
v0.38.3 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 10 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RouteCtxKey is the context.Context key to store the request context.
	RouteCtxKey = context.NewContextKey("RouteContext")
)

Functions

func GetRoutePath added in v0.38.0

func GetRoutePath(req *http.Request) string

GetRoutePath returns the Path to route, either from our RoutingContext, or from the Request's URL

func RouteParams added in v0.33.0

func RouteParams(ctx context.Context) map[string]interface{}

RouteParams returns the Routing map of parameters from a http.Request Context.

func WithRouteContext

func WithRouteContext(ctx context.Context, rctx *RoutingContext) context.Context

WithRouteContext returns a new http.Request Context with a given mix routing Context object connected to it, so it can later be extracted using RouteContext()

Types

type Context

type Context = context.Context

type RoutingContext added in v0.33.0

type RoutingContext struct {
	RoutePrefix  string
	RoutePath    string
	RoutePattern string
	RouteParams  map[string]interface{}
}

func GetRouteContextPath added in v0.38.0

func GetRouteContextPath(req *http.Request) (context.Context, *RoutingContext, string)

GetRouteContextPath returns a RoutingContext and the corresponding RoutePath. If the Context doesn't contain a RoutingContext one will be created

func NewRouteContext

func NewRouteContext(prefix, path string) *RoutingContext

NewRouteContext returns a new RoutingContext object.

func RouteContext

func RouteContext(ctx context.Context) *RoutingContext

RouteContext returns a RoutingContext object from a http.Request Context.

func (*RoutingContext) Add added in v0.33.0

func (rctx *RoutingContext) Add(key string, v interface{})

Append value for a RouteParam

func (RoutingContext) Clone added in v0.33.0

func (rctx RoutingContext) Clone() *RoutingContext

Clone() creates a copy of a RoutingContext object

func (*RoutingContext) Format added in v0.38.0

func (rctx *RoutingContext) Format(f fmt.State, verb rune)

Format formats the RoutingContext according to the fmt.Formatter interface

%s string corresponding to the full path, including prefix %q quoted strings corresponding to prefix and path, separated by a comma %+q same as %q but also including the pattern %v same as %+q %#v same as %v but also including the parameters %# v same as %#v but parameters are indented

func (*RoutingContext) Get added in v0.33.0

func (rctx *RoutingContext) Get(key string) (interface{}, error, bool)

Get item from RouteParams

func (*RoutingContext) GetInt added in v0.33.0

func (rctx *RoutingContext) GetInt(key string) (x int, err error, ok bool)

Get int parameter from RouteContext

func (*RoutingContext) GetIntSlice added in v0.33.0

func (rctx *RoutingContext) GetIntSlice(key string) (x []int, err error, ok bool)

Get slice of int parameters from RouteContext

func (*RoutingContext) GetSlice added in v0.33.0

func (rctx *RoutingContext) GetSlice(key string) (x []interface{}, err error, ok bool)

Get slice of interface{} parameters from RouteContext

func (*RoutingContext) GetString added in v0.33.0

func (rctx *RoutingContext) GetString(key string) (x string, err error, ok bool)

Get string parameter from RouteContext

func (*RoutingContext) GetStringSlice added in v0.33.0

func (rctx *RoutingContext) GetStringSlice(key string) (x []string, err error, ok bool)

Get slice of string parameters from RouteContext

func (*RoutingContext) Init added in v0.33.0

func (rctx *RoutingContext) Init(prefix, path string)

func (*RoutingContext) Next added in v0.33.0

func (rctx *RoutingContext) Next() (*RoutingContext, string)

func (*RoutingContext) Path added in v0.33.0

func (rctx *RoutingContext) Path() string

Path returns to the full path in a string, including prefix

func (*RoutingContext) Set added in v0.33.0

func (rctx *RoutingContext) Set(key string, v interface{})

Sets value for a RouteParam

func (*RoutingContext) Step added in v0.33.0

func (rctx *RoutingContext) Step(prefix string) *RoutingContext

func (*RoutingContext) String added in v0.38.0

func (rctx *RoutingContext) String() string

String returns to the full path in a string, including prefix

Jump to

Keyboard shortcuts

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