methodfunc

package
v8.0.0-...-83b6dc8 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2017 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrStatusCode = 400

DefaultErrStatusCode is the default error status code (400) when the response contains an error which is not nil.

Functions

func DispatchCommon

func DispatchCommon(ctx context.Context,
	statusCode int, contentType string, content []byte, v interface{}, err error, found bool)

DispatchCommon is being used internally to send commonly used data to the response writer with a smart way.

func DispatchErr

func DispatchErr(ctx context.Context, status int, err error)

DispatchErr writes the error to the response.

func DispatchFuncResult

func DispatchFuncResult(ctx context.Context, values []reflect.Value)

DispatchFuncResult is being used internally to resolve and send the method function's output values to the context's response writer using a smart way which respects status code, content type, content, custom struct and an error type. Supports for: func(c *ExampleController) Get() string | (string, string) | (string, int) | ... int | (int, string | (string, error) | ... error | (int, error) | (customStruct, error) | ... bool | (int, bool) | (string, bool) | (customStruct, bool) | ... customStruct | (customStruct, int) | (customStruct, string) | Result or (Result, error) and so on...

where Get is an HTTP METHOD.

Types

type FuncInfo

type FuncInfo struct {
	// Name is the map function name.
	Name string
	// Trailing is not empty when the Name contains
	// characters after the titled method, i.e
	// if Name = Get -> empty
	// if Name = GetLogin -> Login
	// if Name = GetUserPost -> UserPost
	Trailing string

	// The Type of the method, includes the receivers.
	Type reflect.Type

	// Index is the index of this function inside the controller type.
	Index int
	// HTTPMethod is the original http method that this
	// function should be registered to and serve.
	// i.e "GET","POST","PUT"...
	HTTPMethod string
}

FuncInfo is part of the `TController`, it contains the index for a specific http method, taken from user's controller struct.

type MethodFunc

type MethodFunc struct {
	FuncInfo
	// MethodCall fires the actual handler.
	// The "ctx" is the current context, helps us to get any path parameter's values.
	//
	// The "f" is the controller's function which is responsible
	// for that request for this http method.
	// That function can accept one parameter.
	//
	// The default callers (and the only one for now)
	// are pre-calculated by the framework.
	MethodCall func(ctx context.Context, f reflect.Value)
	RelPath    string
}

MethodFunc the handler function.

func Resolve

func Resolve(typ reflect.Type) ([]MethodFunc, error)

Resolve returns all the method funcs necessary information and actions to perform the request.

type Result

type Result interface {
	// Dispatch should sends the response to the context's response writer.
	Dispatch(ctx context.Context)
}

Result is a response dispatcher. All types that complete this interface can be returned as values from the method functions.

Jump to

Keyboard shortcuts

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