Documentation ¶
Overview ¶
Package gong is a simple web framework using chi (http router) and pongo2 (django-syntax template engine). Gong relies heavily on context.Context.
Example:
init() { g := &gong.Gong{} err := g.SetTemplateBaseDir("templates/") if err != nil { panic(err) } r := chi.NewRouter() r.Use(gong.Inject(g)) gong.URL(r, "/", gong.NewView().FromTemplateFile("index.html"). GetFunc(func(w http.ResponseWriter, r *http.Request) { RenderView(r.Context(), pongo2.Context{"name": "value"}, w) })) http.Handle("/", r) }
Index ¶
- func ContextWith(ctx context.Context, g *Gong) context.Context
- func ContextWithTemplateContext(ctx context.Context, c pongo2.Context) context.Context
- func ContextWithView(ctx context.Context, v *View) context.Context
- func Inject(g *Gong) func(http.Handler) http.Handler
- func NotFound(w http.ResponseWriter, r *http.Request)
- func Render(ctx context.Context, c pongo2.Context, t *pongo2.Template, w io.Writer) error
- func RenderView(ctx context.Context, c pongo2.Context, w io.Writer) error
- func ServerError(w http.ResponseWriter, r *http.Request, status int, message string)
- func TemplateContextFromContext(ctx context.Context) pongo2.Context
- func URL(r chi.Router, pattern string, v *View)
- func ViewErrorHandler(filename string) func(http.Handler) http.Handler
- func WithNotFoundHandler(ctx context.Context, h http.Handler) context.Context
- func WithServerErrorHandler(ctx context.Context, h ErrorHandler) context.Context
- type ContextKey
- type ErrorHandler
- type Gong
- type View
- func (v *View) FromTemplateFile(filename string) *View
- func (v *View) Get(get http.Handler) *View
- func (v *View) GetFunc(getf http.HandlerFunc) *View
- func (v *View) Post(post http.Handler) *View
- func (v *View) PostFunc(postf http.HandlerFunc) *View
- func (v *View) Render(ctx context.Context, c pongo2.Context, w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServerError ¶
func WithNotFoundHandler ¶
func WithServerErrorHandler ¶
func WithServerErrorHandler(ctx context.Context, h ErrorHandler) context.Context
Types ¶
type ContextKey ¶
type ContextKey struct {
// contains filtered or unexported fields
}
func (*ContextKey) String ¶
func (c *ContextKey) String() string
type ErrorHandler ¶
type Gong ¶
type Gong struct {
// contains filtered or unexported fields
}
func FromContext ¶
func (*Gong) SetTemplateBaseDir ¶
type View ¶
type View struct {
// contains filtered or unexported fields
}
func ViewFromContext ¶
func (*View) FromTemplateFile ¶
Click to show internal directories.
Click to hide internal directories.