template

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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 AddGlobalModelData(ctx context.Context, model Model, r *http.Request)

func ContextModelValuer

func ContextModelValuer[T any](fn func(ctx context.Context) T) func(context.Context) interface{}

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 RequestModelValuer[T any](fn func(req *http.Request) T) func(req *http.Request) interface{}

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 Model

type Model gin.H

type ModelValuer

type ModelValuer interface {
	~func() interface{} | ~func(ctx context.Context) interface{} | ~func(req *http.Request) interface{}
}

type ModelView

type ModelView struct {
	// View is the name of template file
	View string
	// Model is map[string]interface{}
	Model Model
}

func RedirectView

func RedirectView(location string, statusCode int, ignoreContextPath bool) *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

Jump to

Keyboard shortcuts

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