mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-11-10 23:31:09 +00:00
added documentation comments to methods
This commit is contained in:
@@ -12,6 +12,9 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Auth Middleware.
|
||||
//
|
||||
// Checks if token from header is valid and extracts the id.
|
||||
func Auth(c *gin.Context) {
|
||||
exceptionReturn := new(models.Exception)
|
||||
tokenString := ExtractToken(c)
|
||||
@@ -34,6 +37,7 @@ func Auth(c *gin.Context) {
|
||||
c.Next()
|
||||
}
|
||||
|
||||
// Extracts token from header
|
||||
func ExtractToken(c *gin.Context) string {
|
||||
bearerToken := c.GetHeader("Authorization")
|
||||
tokenArr := strings.Split(bearerToken, " ")
|
||||
@@ -46,6 +50,7 @@ func ExtractToken(c *gin.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Checks if token is valid
|
||||
func CheckToken(tokenString string) (*jwt.Token, error) {
|
||||
secret := os.Getenv("ACCESS_SECRET")
|
||||
if secret == "" {
|
||||
|
||||
@@ -2,6 +2,9 @@ package middleware
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
// CORS Middleware.
|
||||
//
|
||||
// Add needed headers to make cors functioning.
|
||||
func CORSMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
@@ -9,6 +9,9 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Secret Code Middleware.
|
||||
//
|
||||
// Checks if secret code from body is valid.
|
||||
func SecretCode(c *gin.Context) {
|
||||
exceptionReturn := new(models.Exception)
|
||||
secretCode := ExtractCode(c)
|
||||
@@ -26,6 +29,7 @@ func SecretCode(c *gin.Context) {
|
||||
c.Next()
|
||||
}
|
||||
|
||||
// Extracts the secret code from body
|
||||
func ExtractCode(c *gin.Context) SecretCodeModel {
|
||||
secret := new(SecretCodeModel)
|
||||
if err := c.ShouldBindJSON(&secret); err != nil {
|
||||
@@ -37,5 +41,5 @@ func ExtractCode(c *gin.Context) SecretCodeModel {
|
||||
|
||||
type SecretCodeModel struct {
|
||||
SecretCode string `json:"secretCode"`
|
||||
Version string `json:"version"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user