Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Latest commit

 

History

History
53 lines (36 loc) · 1.11 KB

README.md

File metadata and controls

53 lines (36 loc) · 1.11 KB

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)