31 lines
558 B
Go
31 lines
558 B
Go
package rest
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var syncState bool = false
|
|
|
|
func SyncMiddleware() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
qs := c.Request.URL.Query()
|
|
for key, values := range qs {
|
|
fmt.Printf("key = %v, value(s) = %v\n", key, values)
|
|
if key == "sync_state" {
|
|
if values[0] == "true" {
|
|
syncState = true
|
|
} else {
|
|
syncState = false
|
|
}
|
|
}
|
|
}
|
|
if syncState {
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "sync state"})
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|