Giter Club home page Giter Club logo

go-lane-gin's Introduction

Gin Lane

This library implements an adapter for Gin to use lanes for logging and context.

Lanes are contexts, and provide a logging interface. A correlation ID is logged, which is very helpful when following activity of a single request. There are several options for log output, such as Go's standard log, or to disk, or to OpenSearch. And there's a lane to test for log output, and a null lane to supress logging.

See go-lane for more details about lanes.

Use

Instantiation

Instead of calling gin.Default(), call NewGinRouter() instead. This function associates a parent lane with the new Gin router instance. As the router is run, each request gets its own lane derived from the parent.

The request and the response can be logged by specifying one or more options to NewGinRouter(), such as GinLaneOptionLogRequestResult.

If your code is making its own router via gin.New(), call UseLaneMiddleware() to add the lane layer to the router. It usually needs to be the first middleware in the chain.

Logging in Handlers

With the Gin Lane middleware installed in the router, the request's context becomes a lane. Handlers can access the lane instance from the request:

    router.GET("/", func(c *gin.Context) {
        l := c.Request.Context().(lane.Lane)
        l.Infof("processing request...")
    }

Because a lane instance is a context, it can also be used for cancelation of long-running requests, per the typical pattern of Go contexts.

go-lane-gin's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.