Documentation ¶
Index ¶
- Constants
- func AddGlobalModelData(ctx context.Context, model Model, r *http.Request)
- func ContextModelValuer[T any](fn func(ctx context.Context) T) func(context.Context) interface{}
- func RegisterGlobalModelValuer[T ModelValuer](key string, valuer T)
- func RequestModelValuer[T any](fn func(req *http.Request) T) func(req *http.Request) interface{}
- func StaticModelValuer(value interface{}) func() interface{}
- func TemplateEncodeResponseFunc(ctx context.Context, _ http.ResponseWriter, response interface{}) error
- func TemplateErrorEncoder(c context.Context, err error, w http.ResponseWriter)
- type MappingBuilder
- func (b *MappingBuilder) Build() web.TemplateMapping
- func (b *MappingBuilder) Condition(condition web.RequestMatcher) *MappingBuilder
- func (b *MappingBuilder) Get(path string) *MappingBuilder
- func (b *MappingBuilder) Group(group string) *MappingBuilder
- func (b *MappingBuilder) HandlerFunc(endpointFunc ModelViewHandlerFunc) *MappingBuilder
- func (b *MappingBuilder) Method(method string) *MappingBuilder
- func (b *MappingBuilder) Name(name string) *MappingBuilder
- func (b *MappingBuilder) Path(path string) *MappingBuilder
- func (b *MappingBuilder) Post(path string) *MappingBuilder
- type Model
- type ModelValuer
- type ModelView
- type ModelViewHandlerFunc
- type RequestContext
Constants ¶
const ( ModelKeyError = "error" ModelKeyErrorCode = "errorCode" ModelKeyStatusCode = "statusCode" ModelKeyStatusText = "statusText" ModelKeyMessage = "message" ModelKeySession = "session" ModelKeyRequestContext = "rc" ModelKeySecurity = "security" ModelKeyCsrf = "csrf" )
Variables ¶
This section is empty.
Functions ¶
func AddGlobalModelData ¶
func ContextModelValuer ¶
func RegisterGlobalModelValuer ¶
func RegisterGlobalModelValuer[T ModelValuer](key string, valuer T)
RegisterGlobalModelValuer register a ModelValuer with given model key. The registered ModelValuer is applied before any ModelView is rendered. Use StaticModelValuer, ContextModelValuer or RequestModelValuer to wrap values/functions as ModelValuer
func RequestModelValuer ¶
func StaticModelValuer ¶
func StaticModelValuer(value interface{}) func() interface{}
func TemplateEncodeResponseFunc ¶
func TemplateEncodeResponseFunc(ctx context.Context, _ http.ResponseWriter, response interface{}) error
func TemplateErrorEncoder ¶
func TemplateErrorEncoder(c context.Context, err error, w http.ResponseWriter)
Types ¶
type MappingBuilder ¶
type MappingBuilder struct {
// contains filtered or unexported fields
}
MappingBuilder builds web.TemplateMapping using web.GinBindingRequestDecoder, TemplateEncodeResponseFunc and TemplateErrorEncoder MappingBuilder.Path, MappingBuilder.Method and MappingBuilder.HandlerFunc are required to successfully build a mapping. See ModelViewHandlerFunc for supported strongly typed function signatures. Example: <code> template.Post("/path/to/page").HandlerFunc(func...).Build() </code>
func Any ¶
func Any(path string) *MappingBuilder
func Get ¶
func Get(path string) *MappingBuilder
func New ¶
func New(names ...string) *MappingBuilder
func Post ¶
func Post(path string) *MappingBuilder
func (*MappingBuilder) Build ¶
func (b *MappingBuilder) Build() web.TemplateMapping
func (*MappingBuilder) Condition ¶
func (b *MappingBuilder) Condition(condition web.RequestMatcher) *MappingBuilder
func (*MappingBuilder) Get ¶
func (b *MappingBuilder) Get(path string) *MappingBuilder
func (*MappingBuilder) Group ¶
func (b *MappingBuilder) Group(group string) *MappingBuilder
func (*MappingBuilder) HandlerFunc ¶
func (b *MappingBuilder) HandlerFunc(endpointFunc ModelViewHandlerFunc) *MappingBuilder
func (*MappingBuilder) Method ¶
func (b *MappingBuilder) Method(method string) *MappingBuilder
func (*MappingBuilder) Name ¶
func (b *MappingBuilder) Name(name string) *MappingBuilder
func (*MappingBuilder) Path ¶
func (b *MappingBuilder) Path(path string) *MappingBuilder
func (*MappingBuilder) Post ¶
func (b *MappingBuilder) Post(path string) *MappingBuilder
type ModelValuer ¶
type ModelView ¶
type ModelViewHandlerFunc ¶
type ModelViewHandlerFunc interface{}
ModelViewHandlerFunc is a function with following signature
- two input parameters with 1st as context.Context and 2nd as <request>
- two output parameters with 1st as <response> and 2nd as error
where <request>: a struct or a pointer to a struct whose fields are properly tagged <response>: a pointer to a ModelView. e.g.: func(context.Context, request *AnyStructWithTag) (response *ModelView, error) {...}
type RequestContext ¶
type RequestContext map[string]interface{}
func MakeRequestContext ¶
func MakeRequestContext(ctx context.Context, r *http.Request) RequestContext
MakeRequestContext collect http.Request's exported fields and additional context values