echo_ext

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: MIT Imports: 8 Imported by: 0

README

echo_ext

中文/Chinese

Description

A packet extending echo. Add circuit breaker and error handler etc...

echo_ext

It includes logger error_handler context_enhance and extends echo

description
logger use a log.Logger to bridge echo.Logger,have access to log.Logger Unified printing.
error_handler in debug mode, use pkg/error to return all error messages.
context_enhance added some methods of context
middleware_ext

it adds access_log circuit_breaker logger_adapter echo middleware

Synopsis

access_log
package main

import (
	"github.com/baishan-development-guizhou/golang-library/echo_ext/middleware_ext"
	"github.com/baishan-development-guizhou/golang-library/log"
	"github.com/labstack/echo/v4"
	"net/http"
)

func main() {
	engine := echo.New()
	log.ReplaceG(log.Configure().WithOutputEncoder(log.ConsoleOutputEncoder).Init())
	engine.Use(middleware_ext.LoggerAdapter())
	engine.Use(middleware_ext.AccessLog())
	engine.GET("/", func(context echo.Context) error {
		return context.JSON(http.StatusOK, echo.Map{"message": "ok"})
	})
	_ = engine.Start(":8080")

}


error_handler
package main

import (
	"errors"
	"github.com/baishan-development-guizhou/golang-library/echo_ext"
	"github.com/baishan-development-guizhou/golang-library/echo_ext/middleware_ext"
	"github.com/baishan-development-guizhou/golang-library/log"
	"github.com/labstack/echo/v4"
	"net/http"
)

func main() {

	engine := echo.New()
	engine.Debug = true
	log.ReplaceG(log.Configure().WithOutputEncoder(log.ConsoleOutputEncoder).WithNamed("[nefarian]").Init())
	engine.Use(middleware_ext.LoggerAdapter())
	engine.HTTPErrorHandler = echo_ext.HttpErrorHandler
	engine.GET("/", func(context echo.Context) error {
		return echo.NewHTTPError(http.StatusInternalServerError, "sdsfs").SetInternal(errors.New("asf"))
	})
	_ = engine.Start(":8080")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpErrorHandler

func HttpErrorHandler(err error, c echo.Context)

HttpErrorHandler

func NewEchoLoggerWithGLogger

func NewEchoLoggerWithGLogger(logger glog.Logger) echo.Logger

func NewPlaygroundValidator

func NewPlaygroundValidator() echo.Validator

Types

type Context

type Context struct {
	echo.Context
}

func ContextEnhance

func ContextEnhance(ctx echo.Context) *Context

ContextEnhance make context easy to use

func (*Context) BindValidate

func (c *Context) BindValidate(i interface{}) error

type PlaygroundValidator

type PlaygroundValidator struct {
	// contains filtered or unexported fields
}

func (*PlaygroundValidator) Validate

func (c *PlaygroundValidator) Validate(i interface{}) error

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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