middleware

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: MIT Imports: 11 Imported by: 0

README

Package Middleware

This package contains http middleware. The middleware are actually a pure http.Handler. We keep the handler in this way since it's the form that compatible with golang standard.

JWT Middleware

JWT middleware is middleware for checking whether token is valid or not.

Log Middleware

Log middleware is middleware that will help logging the application. The logging prints out log from Kitabisa log specification.

How To Use The Middleware

func main() {
	meta := structs.Meta{
		Version: "v1.2.3",
		Status:  "stable",
		APIEnv:  "prod-test",
	}

	handlerCtx := phttp.NewContextHandler(meta)
	
	newHandler := phttp.NewHttpHandler(handlerCtx)
	helloHandler := newHandler(HelloHandler)

    // middleware initialization. Just initialized it and use.
	midd := middleware.NewJWTMiddleware(handlerCtx, []byte("abcde"))
	logMiddleware := middleware.NewHttpRequestLoggerMiddleware(logger)

	router := chi.NewRouter()
    
    // use the middleware
    router.Use(midd)
    router.Use(logMiddleware)
    
	router.Get("/", helloHandler.ServeHTTP)

	http.ListenAndServe(":5678", router)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHeaderCheck added in v2.7.0

func NewHeaderCheck(hctx phttp.HttpHandlerContext, secretKey string) func(next http.Handler) http.Handler

func NewHttpRequestLogger added in v2.7.0

func NewHttpRequestLogger(logger *log.Logger) func(next http.Handler) http.Handler

func NewJWT added in v2.7.0

func NewJWT(hctx phttp.HttpHandlerContext, signKey []byte) func(next http.Handler) http.Handler

Types

type Header struct {
	XKtbsRequestID     string `valid:"uuidv4,required"`
	XKtbsApiVersion    string `valid:"semver,required"`
	XKtbsClientVersion string `valid:"semver,required"`
	XKtbsPlatformName  string `valid:"required"`
	XKtbsClientName    string `valid:"required"`

	// Optional
	XKtbsSignature string `valid:"optional"`
	XKtbsTime      string `valid:"int,optional"`
	Authorization  string `valid:"optional"`
}

type HttpRequestLoggerMiddleware

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

Jump to

Keyboard shortcuts

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