golibgin

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 13 Imported by: 0

README

Golib GIN

Note We are moving out from Gitlab. All packages are now migrated to github.com/golibs-starter/*. Please consider updating.

Gin Wrapper to adapt with GoLib

Setup instruction

Base setup, see GoLib Instruction

Both go get and go mod are supported.

go get github.com/golibs-starter/golib-gin
Usage

Using fx.Option to include dependencies for injection.

package main

import (
    "github.com/golibs-starter/golib-gin"
    "go.uber.org/fx"
)

func main() {
    fx.New(
        // Using Gin as handler for Http Server,
        // Append startup method to Fx OnStart lifecycle.
        golibgin.GinHttpServerOpt(),

        // When you want to enable graceful shutdown.
        golibgin.OnStopHttpServerOpt(),
    ).Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomRecovery

func CustomRecovery(handle gin.RecoveryFunc) gin.HandlerFunc

CustomRecovery returns a middleware that recovers from any panics and calls the provided handle func to handle it.

func DefaultHandleRecovery

func DefaultHandleRecovery(c *gin.Context, err interface{})

func GinHttpServerOpt

func GinHttpServerOpt() fx.Option

func InitContext

func InitContext() gin.HandlerFunc

func New

func New() (http.Handler, func(h http.Handler) gin.HandlerFunc)

func NewGinEngine

func NewGinEngine(in GinEngineIn) *gin.Engine

func NewHTTPServer

func NewHTTPServer(app *golib.App, engine *gin.Engine) *http.Server

func OnStartHttpServerHook

func OnStartHttpServerHook(lc fx.Lifecycle, app *golib.App, httpServer *http.Server)

func OnStopHttpServerHook

func OnStopHttpServerHook(lc fx.Lifecycle, httpServer *http.Server)

func OnStopHttpServerOpt

func OnStopHttpServerOpt() fx.Option

func Recovery

func Recovery() gin.HandlerFunc

func RegisterHandlers

func RegisterHandlers(app *golib.App, engine *gin.Engine)

func StartOpt

func StartOpt() fx.Option

StartOpt Deprecated: Using GinHttpServerOpt in bootstrap options instead

func Wrap

func Wrap(f func(h http.Handler) http.Handler) gin.HandlerFunc

Wrap takes the common HTTP middleware function signature, calls it to generate a handler, and wraps it into a Gin middleware handler. This is just a convenience wrapper around New.

func WrapAll

func WrapAll(hh []func(h http.Handler) http.Handler) []gin.HandlerFunc

WrapAll allow wrapping multiple http.Handler, returns a slice of gin.HandlerFunc

Types

type GinEngineIn

type GinEngineIn struct {
	fx.In
	Logging *log.Properties `optional:"true"`
}

Jump to

Keyboard shortcuts

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