echox

package module
v0.0.0-...-cabd6b2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2016 License: MIT Imports: 0 Imported by: 0

README

EchoX

License GoDoc Build Status Coverage Status

Overview

EchoX is extensions library for Echo web framework.

Loggers

package main

import (
    "net/http"
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
    "github.com/o1egl/echox/log"
)

func main() {
    e := echo.New()
    e.SetLogger(log.Logrus())
    e.GET("/", func(c echo.Context) error {
        return c.String(http.StatusOK, "Hello, World!")
    })
    e.Run(standard.New(":1323"))
}

Template loaders

If you have the following hierarchy:

public/
     css/
     js/
     images/
     templates/
  1. File system loader

     loader := template.FSLoader("public/templates")
    
  2. go-bindata in memory loader

    First you need to generate bin data file

    $ go get -u github.com/jteeuwen/go-bindata/...
    $ go-bindata -o assets/assets.go -pkg=assets -prefix=public public/...
    
     loader := template.GOBinDataLoader("templates", assets.AssetDir, assets.Asset)
    

Template renderers

html renderer
package main

import (
    "net/http"
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
    "github.com/o1egl/echox/template"
)

func main() {
    e := echo.New()
    e.SetRenderer(template.HTML(template.FSLoader("public/templates")))
    e.GET("/", func(c echo.Context) error {
        return c.Render(http.StatusOK, "hello", map[string]interface{}{"Name": "Joe"})
    })
    e.Run(standard.New(":1323"))
}
Fasttemplate renderer
package main

import (
    "net/http"
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
    "github.com/o1egl/echox/template"
)

func main() {
    e := echo.New()
    e.SetRenderer(template.HTML(template.FSLoader("public/templates")))
    e.GET("/", func(c echo.Context) error {
        return c.Render(http.StatusOK, "hello.html", map[string]interface{}{"Name": "Joe"})
    })
    e.Run(standard.New(":1323"))
}
Pongo2 renderer
package main

import (
    "net/http"
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
    "github.com/o1egl/echox/template"
)

func main() {
    e := echo.New()
    e.SetRenderer(template.Pongo(template.FSLoader("public/templates")))
    e.GET("/", func(c echo.Context) error {
        return c.Render(http.StatusOK, "hello.html", map[string]interface{}{"name": "Joe"})
    })
    e.Run(standard.New(":1323"))
}

Submitting a Pull Request

  1. Fork it.
  2. Create a branch (git checkout -b my_branch)
  3. Commit your changes (git commit -am "Added new awesome logger")
  4. Push to the branch (git push origin my_branch)
  5. Open a Pull Request
  6. Enjoy a refreshing Diet Coke and wait

Documentation

Overview

echox (Echo Extensions) is a bundle of third party extensions for Echo web framework

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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