maryread

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

README

Mary Read

Provides a echo router wrapper with extra functionality like database initialization and util working middleware to be shared between microservices. Also helps to fight global warming acting as Mary Read

App

Default

Provides an app with default tools:

  • A new echo router Usage:
    import "github.com/orov-io/maryRead
    // ...

    app := maryread.Default()
    // You can access to the new echo router by app.Router()
    // app.Router().Use()
    // app.Router().GET()...
    

Custom App

Returns an app with tools configured via options: Usage:

    import "github.com/orov-io/maryRead
    // ...

    e := echo.New()
    // e.GET()....
    options := maryread.AppOptions{
        Router: RouterOptions{
            Router: router
        }
    }
    

Available Middleware

    import "github.com/orov-io/maryRead/middleware"

Body Dump

Adds the default Bodydump echo middleware for request with the header X-Bodydump not empty. Usage:

e := echo.New()
e.Use(DefaultLogger(zerolog.DebugLevel))
e.Use(BodyDumpOnHeader())

It relies in the logger echo-midlleware (see below) After this, all request with the X-Bodydump will use the zero logger functionality in this package to log both request & response bodies.

Logger

Usage:

e := echo.New()
e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
    SigningKey: []byte(testJWTSecret),
}))
e.Use(DefaultLogger(zerolog.DebugLevel))

Adds the zero logger to the echo context. It generates a child that:

  • Adds the requestID if the requestID (the one in this package or the one prodived by echo) as a string param.
  • Adds the userID if you uses the JWT echo middleware a a string params. At now, it spects the ID to be in the ID claim.
  • Uses a pretty zerolog parser.
  • Changes the log level for a single request if you send the X-Loglevel header set to a valid zerolog level value (trace, debug, info ...)

RequestID

Usage:

e := echo.New()
e.Use(middleware.RequestID())
// Inside a handler or middleware...
RequestID(c) # It returns the generated requestID

Returns the generated requestID if you use the echo requestID middleware

Request Logger

Usage

e := echo.New()
e.Use(DefaultLogger(zerolog.DebugLevel))
e.Use(DefaultRequestZeroLoggerConfig())

It relies in the provided logger functionality, like the body dump middleware. Use the zerologger and the echo requestLogger middleware to log request info.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogger

func GetLogger(c echo.Context) zerolog.Logger

GetLogger is a shortcut to middleware.GetLogger()

func RequestID

func RequestID(c echo.Context) string

RequestID is a shortcut to middleware.RequestID()

Types

type App added in v0.0.5

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

func Default added in v0.0.5

func Default() *App

Returns a new app with default values.

func New added in v0.0.5

func New(options AppOptions) *App

NewApp generates a new app with tools expecified in provided options.

func (*App) Router added in v0.0.5

func (app *App) Router() *echo.Echo

Router returns the inner echo router.

type AppOptions added in v0.0.5

type AppOptions struct {
	Router RouterOptions
}

AppOptions models the app tools.

type RouterOptions added in v0.0.5

type RouterOptions struct {
	Router *echo.Echo
}

RouterOptions model the echo router options. If provided, app will use the expecified echo router.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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