24 lines
413 B
Go
24 lines
413 B
Go
package router
|
|
|
|
import (
|
|
"electricity_bill_calc/cache"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AuthenticatedSession(c *gin.Context) {
|
|
auth := c.Request.Header.Get("Authorization")
|
|
if len(auth) > 0 {
|
|
token := strings.Fields(auth)[1]
|
|
session, err := cache.RetreiveSession(token)
|
|
|
|
if err != nil {
|
|
c.AbortWithStatus(http.StatusForbidden)
|
|
}
|
|
c.Set("session", session)
|
|
}
|
|
c.Next()
|
|
}
|