Skip to content

Add some helpful helper function for Echo Go web framework's Context.

License

Notifications You must be signed in to change notification settings

khon-kaen-university/echo-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

echo-context

Add some helpful helper function for Echo 4 Go web framework's Context.

Example

package main

import (
  "net/http"
  "github.com/labstack/echo/v4"
  "github.com/labstack/echo/v4/middleware"
  zercleCTX "github.com/khon-kaen-university/echo-context"
)

func main() {
  // Echo instance
  e := echo.New()

  // Middleware
  e.Use(middleware.Logger())
  e.Use(middleware.Recover())

  // Use in middleware
  e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
    return func(c echo.Context) error {
      ctx := &zercleCTX.Context{c}
      return next(ctx)
    }
  })

  // Use in routes
  e.GET("/", func(c echo.Context) error {
    // ctx := c.(*zercleCTX.Context)
    ctx := &zercleCTX.Context{c}
    name := ctx.FormValueDefault("name", "Anonymous")
    return ctx.String(http.StatusOK, "Hello " + name)
  })

  // Start server
  e.Logger.Fatal(e.Start(":8080"))
}

About

Add some helpful helper function for Echo Go web framework's Context.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages