You've already forked golang-base-project
Adds godoc comments
This commit is contained in:
@ -6,8 +6,10 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// UserIDKey is the key used to set and get the user id in the context of the current request
|
||||
const UserIDKey = "UserID"
|
||||
|
||||
// Auth middleware redirects to /login and aborts the current request if there is no authenticated user
|
||||
func Auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
_, exists := c.Get(UserIDKey)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Cache middleware sets the Cache-Control header
|
||||
func Cache(maxAge int) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Header("Cache-Control", fmt.Sprintf("public, max-age=%d", maxAge))
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var SessionIdentifierKey = "SESSION_IDENTIFIER"
|
||||
|
||||
// NoAuth is for routes that can only be accessed when the user is unauthenticated
|
||||
func NoAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
@ -8,10 +8,14 @@ import (
|
||||
"log"
|
||||
)
|
||||
|
||||
// SessionIDKey is the key used to set and get the session id in the context of the current request
|
||||
const SessionIDKey = "SessionID"
|
||||
|
||||
// Session middleware checks for an active session and sets the UserIDKey to the context of the current request if found
|
||||
func Session(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
sessionIdentifierInterface := session.Get(SessionIdentifierKey)
|
||||
sessionIdentifierInterface := session.Get(SessionIDKey)
|
||||
|
||||
if sessionIdentifier, ok := sessionIdentifierInterface.(string); ok {
|
||||
ses := models.Session{
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Throttle middleware takes a limit per minute and blocks any additional requests that go over this limit
|
||||
func Throttle(limit int) gin.HandlerFunc {
|
||||
store := memory.NewStore()
|
||||
|
||||
|
Reference in New Issue
Block a user