github.com/o1egl/echox/log

Extensions library for echo framework (https://github.com/labstack/echo)


License
MIT
Install
go get github.com/o1egl/echox/log

Documentation

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