EchoMiddleware - Echo Middleware with golang

EchoMiddleware

middleware for echo server

usage

import (
	"github.com/universe-30/EchoMiddleware"  // logger and panic handle
	"github.com/universe-30/EchoMiddleware/tool"  // use Jsoniter as json parser
)

example

package main

import (
	"log"
	"net/http"

	"github.com/labstack/echo/v4"
	"github.com/universe-30/EchoMiddleware"
	"github.com/universe-30/EchoMiddleware/tool"
	"github.com/universe-30/LogrusULog"
	"github.com/universe-30/ULog"
)

func main() {
	// need a logger which implements ULog.Logger interface
	// here use LogrusULog as example
	logger, _ := LogrusULog.New("./logs", 2, 20, 30)
	logger.SetLevel(ULog.DebugLevel)

	// new echo instance
	hs := echo.New()

	//use Jsoniter as json parser
	hs.JSONSerializer = tool.NewJsoniter()

	//use logger middleware
	hs.Use(EchoMiddleware.LoggerWithConfig(EchoMiddleware.LoggerConfig{
		Logger: logger, //Logger interface
	}))

	//use recover and panic handler
	hs.Use(EchoMiddleware.RecoverWithConfig(EchoMiddleware.RecoverConfig{
		// callback to handler panic
		OnPanic: func(panic_err interface{}) {
			log.Println(panic_err)
		},
	}))

	///////////////////  JSONP //////////////////////
	hs.GET("/test1", func(c echo.Context) error {
		return c.String(http.StatusOK, "success test1")
	})

	hs.GET("/test2", func(c echo.Context) error {
		//example panic happen
		a := 1
		_ = 1 / (a - 1)

		return c.String(http.StatusOK, "success test2")
	})

	// start server
	hs.Start(":8080")
}
Similar Resources

A minimal framework to build web apps; with handler chaining, middleware support; and most of all standard library compliant HTTP handlers(i.e. http.HandlerFunc).

A minimal framework to build web apps; with handler chaining, middleware support; and most of all standard library compliant HTTP handlers(i.e. http.HandlerFunc).

WebGo v4.1.3 WebGo is a minimalistic framework for Go to build web applications (server side) with zero 3rd party dependencies. Unlike full-fledged fr

Jan 1, 2023

Gzip Middleware for Go

 Gzip Middleware for Go

An out-of-the-box, also customizable gzip middleware for Gin and net/http.

Dec 19, 2022

Prometheus middleware for wish

Prometheus middleware for wish

promwish Package promwish provides a simple wish middleware exposing some Prometheus metrics. Example Usage You can add promwish as a middleware to yo

Nov 26, 2022

X-Response-Time middleware for fiber/v2

fiber-responsetime X-Response-Time middleware for fiber/v2 go get github.com/husanu/fiber-responsetime/v2 package main import ( "time" "github.com

Dec 17, 2021

Gin middleware/handler to enable CORS support.

wcors Gin middleware/handler to enable CORS support. Usage Start using it Download and install it: go get github.com/wyy-go/wcors Import it in your co

Jan 8, 2022

Episodio V: Rise of the middleware

APITrials0.5 Episodio V: Rise of the middleware Captain's log: Up to date this file contains some simple errors to be corrected. They come from severa

Jan 10, 2022

⚡Simple cors middleware package for minima

⚡Simple cors middleware package for minima

This is package is wrapper based on rs/cors package made for minima. Geting Started Install the package using go get github.com/gominima/cors and call

Mar 7, 2022

Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Jan 3, 2023

BANjO is a simple web framework written in Go (golang)

BANjO banjo it's a simple web framework for building simple web applications Install $ go get github.com/nsheremet/banjo Example Usage Simple Web App

Sep 27, 2022
Auth0 Middleware for go labstack/echo

go-echo-auth0-middleware Auth0 Middleware for go labstack/echo Example package main import ( "net/http" "github.com/auth0/go-jwt-middleware/v2/val

Nov 24, 2022
Golang Echo Framework

template-golang-echo Creator: 한승진 Date: 2021/10/13 Description Kubernetes-Istio 환경인 리얼패킹 클라우드에 배포하기 위한 Golang Echo 서버 기초 템플릿입니다. 배포 타겟 기술스텍 : Kubernet

Oct 13, 2021
Simple REST-API implementation using Golang with several packages (Echo, GORM) and Docker

Simple REST-API Boilerplate This is a simple implementation of REST-API using Golang and several packages (Echo and GORM). By default, I use PostgreSQ

Sep 13, 2022
A Golang restful API boilerplate based on Echo framework v4

A Golang restful API boilerplate based on Echo framework v4. Includes tools for module generation, db migration, authorization, authentication and more.

Nov 15, 2022
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger

CRUD API Server of Clean Architecture Go(echo) gorm mysql docker swagger build docker-compose up -d --build API Postman and Fiddler is recommended to

May 14, 2022
REST API boilerplate built with go and clean architecture - Echo Framework

GO Boilerplate Prerequisite Install go-migrate for running migration https://github.com/golang-migrate/migrate App requires 2 database (postgreSQL an

Jan 2, 2023
REST API with Echo Framework from Go
REST API with Echo Framework from Go

REST API with Echo Framework from Go

Nov 16, 2021
It took me a while to figure out how I can use GraphQL with the ent ORM and serve the GraphQL endpoint via the Echo framework

Go + Graphql + Ent + Echo Boilerplate It took me a while to figure out how I can use GraphQL with the ent ORM and serve the GraphQL endpoint via the E

Sep 28, 2022
Goa is a web framework based on middleware, like koa.js.

Goa Goa is under construction, if you are familiar with koa or go and interested in this project, please join us. What is goa? goa = go + koa Just lik

Sep 27, 2022
⚡ Rux is an simple and fast web framework. support middleware, compatible http.Handler interface. 简单且快速的 Go web 框架,支持中间件,兼容 http.Handler 接口

Rux Simple and fast web framework for build golang HTTP applications. NOTICE: v1.3.x is not fully compatible with v1.2.x version Fast route match, sup

Dec 8, 2022