mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
fixed code documentation
This commit is contained in:
@@ -12,9 +12,13 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Auth Middleware.
|
||||
//
|
||||
// Checks if token from header is valid and extracts the id.
|
||||
/*
|
||||
Auth
|
||||
|
||||
Checks if token from header is valid and extracts the id.
|
||||
Args:
|
||||
*gin.Context: Gin Application Context.
|
||||
*/
|
||||
func Auth(c *gin.Context) {
|
||||
exceptionReturn := new(models.Exception)
|
||||
tokenString := ExtractToken(c)
|
||||
@@ -37,7 +41,15 @@ func Auth(c *gin.Context) {
|
||||
c.Next()
|
||||
}
|
||||
|
||||
// Extracts token from header
|
||||
/*
|
||||
ExtractToken
|
||||
|
||||
Extracts token from header
|
||||
Args:
|
||||
*gin.Context: Gin Application Context.
|
||||
Returns:
|
||||
string: Token extracted from context header
|
||||
*/
|
||||
func ExtractToken(c *gin.Context) string {
|
||||
bearerToken := c.GetHeader("Authorization")
|
||||
tokenArr := strings.Split(bearerToken, " ")
|
||||
@@ -50,7 +62,16 @@ func ExtractToken(c *gin.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Checks if token is valid
|
||||
/*
|
||||
CheckToken
|
||||
|
||||
Checks if token is valid
|
||||
Args:
|
||||
string: Token to check
|
||||
Returns:
|
||||
*jwt.Token: Parsed token
|
||||
error: Returns if token is invalid or there was an error inside jwt.Parse function
|
||||
*/
|
||||
func CheckToken(tokenString string) (*jwt.Token, error) {
|
||||
secret := os.Getenv("ACCESS_SECRET")
|
||||
if secret == "" {
|
||||
|
||||
@@ -2,9 +2,13 @@ package middleware
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
// CORS Middleware.
|
||||
//
|
||||
// Add needed headers to make cors functioning.
|
||||
/*
|
||||
CORSMiddleware
|
||||
|
||||
Add needed headers to make cors functioning.
|
||||
Args:
|
||||
*gin.Context: Gin Application Context.
|
||||
*/
|
||||
func CORSMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
@@ -9,9 +9,13 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Secret Code Middleware.
|
||||
//
|
||||
// Checks if secret code from body is valid.
|
||||
/*
|
||||
SecretCode
|
||||
|
||||
Checks if secret code from body is valid.
|
||||
Args:
|
||||
*gin.Context: Gin Application Context.
|
||||
*/
|
||||
func SecretCode(c *gin.Context) {
|
||||
exceptionReturn := new(models.Exception)
|
||||
secretCode := ExtractCode(c)
|
||||
@@ -29,7 +33,13 @@ func SecretCode(c *gin.Context) {
|
||||
c.Next()
|
||||
}
|
||||
|
||||
// Extracts the secret code from body
|
||||
/*
|
||||
ExtractCode
|
||||
|
||||
Extracts the secret code from body.
|
||||
Args:
|
||||
*gin.Context: Gin Application Context.
|
||||
*/
|
||||
func ExtractCode(c *gin.Context) SecretCodeModel {
|
||||
secret := new(SecretCodeModel)
|
||||
if err := c.ShouldBindJSON(&secret); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user