Categorygithub.com/zblocks/middleware-lib
repository
1.0.1
Repository: https://github.com/zblocks/middleware-lib.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Middleware library to handle jwt

Work with library

  1. import the package using the commands in your project
import (
	"github.com/zblocks/middleware-lib"
)

Inside terminal run

go get github.com/zblocks/middleware-lib

  1. Functions included in the library
func VerifyJwtToken(c *gin.Context, jwtSecret string) (bool, jwt.MapClaims, int, error)
func SetCors(r *gin.Engine) 
  1. Variables defined in the library
var ErrAuthorizationTokenEmpty = 20003
var ErrAuthorizationTokenInvalid = 20004

var AuthorizationTokenEmpty = "authorization token not provided"
var AuthorizationTokenInvalid = "authorization token invalid"

Mock middleware in test

Example mocking middleware functions VerifyJwtTokenV2() in your service

  1. In your test function replace MiddlewareHandler interface with the mock interface
middleware.MiddlewareHandler = middlewareMock.MiddlewareMock
  1. Define mocking behavior for the function
	middlewareMock.MiddlewareMock.On("VerifyJwtTokenV2", mock.AnythingOfType("*gin.Context"), "<auth_service_base_url>").Return(true)