ginview

package
v0.1.1-0...-0d14397 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2019 License: MIT Imports: 4 Imported by: 0

README

GinView

GoDoc Widget

goview support for gin template

Install


go get -u github.com/foolin/goview

go get -u github.com/foolin/goview/supports/ginview

Example

package main

import (
	"github.com/foolin/goview/supports/ginview"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	router := gin.Default()

	//new template engine
	router.HTMLRender = ginview.Default()

	router.GET("/", func(ctx *gin.Context) {
		//render with master
		ctx.HTML(http.StatusOK, "index", gin.H{
			"title": "Index title!",
			"add": func(a int, b int) int {
				return a + b
			},
		})
	})

	router.GET("/page", func(ctx *gin.Context) {
		//render only file, must full name with extension
		ctx.HTML(http.StatusOK, "page.html", gin.H{"title": "Page file title!!"})
	})

	router.Run(":9090")
}

Project structure:

|-- app/views/
    |--- index.html          
    |--- page.html
    |-- layouts/
        |--- footer.html
        |--- master.html
    

See in "examples/basic" folder

Gin example

More examples

See _examples/ for a variety of examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTML

func HTML(ctx *gin.Context, code int, name string, data interface{})

HTML function TemplateEngine and make `HTML()` work validly.

func Middleware

func Middleware(e *ViewEngine) gin.HandlerFunc

Middleware function You should use helper func `Middleware()` to set the supplied

func NewMiddleware

func NewMiddleware(config goview.Config) gin.HandlerFunc

NewMiddleware create new gin middleware

Types

type ViewEngine

type ViewEngine struct {
	*goview.ViewEngine
}

ViewEngine struct

func Default

func Default() *ViewEngine

Default function

func New

func New(config goview.Config) *ViewEngine

New function

func (*ViewEngine) HTML

func (e *ViewEngine) HTML(ctx *gin.Context, code int, name string, data interface{})

HTML method

func (*ViewEngine) Instance

func (e *ViewEngine) Instance(name string, data interface{}) render.Render

Instance method

type ViewRender

type ViewRender struct {
	Engine *ViewEngine
	Name   string
	Data   interface{}
}

ViewRender struct

func (ViewRender) Render

func (v ViewRender) Render(w http.ResponseWriter) error

Render (YAML) marshals the given interface object and writes data with custom ContentType.

func (ViewRender) WriteContentType

func (v ViewRender) WriteContentType(w http.ResponseWriter)

WriteContentType method

Jump to

Keyboard shortcuts

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