Skip to content

Commit

Permalink
fix: golint
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasfeijo committed Oct 14, 2022
1 parent 9e036e1 commit 60b196e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions middlewares/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package middlewares

import "github.com/gin-gonic/gin"

// Middleware ...
type Middleware interface {
Run()
}

// InitializeMiddlewares ...
func InitializeMiddlewares() {
NewVerifyAPIKeyMiddleware()
}
Expand Down
10 changes: 9 additions & 1 deletion middlewares/verify_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,33 @@ import (
"github.com/spf13/viper"
)

// VerifyAPIKeyMiddleware ...
type VerifyAPIKeyMiddleware struct {
key string
}

var verifyAPIKeyMiddleware *VerifyAPIKeyMiddleware

// Middleware function to verify the JWT token
// VerifyAPIKey ...
func VerifyAPIKey() gin.HandlerFunc {
return verifyAPIKeyMiddleware.Run()
}

// NewVerifyAPIKeyMiddleware ...
func NewVerifyAPIKeyMiddleware() {
verifyAPIKeyMiddleware = &VerifyAPIKeyMiddleware{
key: viper.GetString("RESOLVER_API_KEY"),
}
}

// Run ...
func (m *VerifyAPIKeyMiddleware) Run() gin.HandlerFunc {
return func(c *gin.Context) {
if m.key == "" {
c.Next()
return
}

key := m.extractKeyFromHeader(c)

if key != m.key {
Expand Down

0 comments on commit 60b196e

Please sign in to comment.