added documentation comments to methods

This commit is contained in:
Fran Jurmanovic
2021-08-02 10:19:58 -07:00
parent 05a13112f1
commit 0195528428
31 changed files with 175 additions and 33 deletions

View File

@@ -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 == "" {

View File

@@ -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", "*")

View File

@@ -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"`
}