gong

package
v0.0.0-...-5b25691 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWith

func ContextWith(ctx context.Context, g *Gong) context.Context

func ContextWithTemplateContext

func ContextWithTemplateContext(ctx context.Context, c pongo2.Context) context.Context

func ContextWithView

func ContextWithView(ctx context.Context, v *View) context.Context

func Inject

func Inject(g *Gong) func(http.Handler) http.Handler

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request)

func Render

func Render(ctx context.Context, c pongo2.Context, t *pongo2.Template, w io.Writer) error

func RenderView

func RenderView(ctx context.Context, c pongo2.Context, w io.Writer) error

func ServerError

func ServerError(w http.ResponseWriter, r *http.Request, status int, message string)

func TemplateContextFromContext

func TemplateContextFromContext(ctx context.Context) pongo2.Context

func URL

func URL(r chi.Router, pattern string, v *View)

func ViewErrorHandler

func ViewErrorHandler(filename string) func(http.Handler) http.Handler

func WithNotFoundHandler

func WithNotFoundHandler(ctx context.Context, h http.Handler) context.Context

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 ErrorHandler interface {
	ServeError(w http.ResponseWriter, r *http.Request, message string, status int) error
}

type Gong

type Gong struct {
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) *Gong

func (*Gong) SetTemplateBaseDir

func (g *Gong) SetTemplateBaseDir(dir string) error

func (*Gong) TemplateFromFile

func (g *Gong) TemplateFromFile(filename string) (*pongo2.Template, error)

type View

type View struct {
	// contains filtered or unexported fields
}

func NewView

func NewView() *View

func ViewFromContext

func ViewFromContext(ctx context.Context) *View

func (*View) FromTemplateFile

func (v *View) FromTemplateFile(filename string) *View

func (*View) Get

func (v *View) Get(get http.Handler) *View

func (*View) GetFunc

func (v *View) GetFunc(getf http.HandlerFunc) *View

func (*View) Post

func (v *View) Post(post http.Handler) *View

func (*View) PostFunc

func (v *View) PostFunc(postf http.HandlerFunc) *View

func (*View) Render

func (v *View) Render(ctx context.Context, c pongo2.Context, w io.Writer) error

Jump to

Keyboard shortcuts

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