change to use logging instead of print to stdout

This commit is contained in:
2023-04-03 12:00:01 +10:00
parent f2ac6097d6
commit 5cc67501d3
11 changed files with 88 additions and 87 deletions

View File

@@ -1,8 +1,8 @@
package controllers
import (
"fmt"
"html"
"log"
"net/http"
"strings"
@@ -39,7 +39,7 @@ func Register(c *gin.Context) {
// Default to regular user role if not specified
if input.RoleId == 0 {
fmt.Printf("Register no role specified, defaulting to RoleId of 2.\n")
log.Printf("Register no role specified, defaulting to RoleId of 2.\n")
u.RoleId = 2
} else {
u.RoleId = input.RoleId
@@ -50,9 +50,9 @@ func Register(c *gin.Context) {
// Check if user already exists
testUser, _ := models.GetUserByName(u.UserName)
fmt.Printf("Register checking if user already exists : '%v'\n", testUser)
log.Printf("Register checking if user already exists : '%v'\n", testUser)
if (models.User{} == testUser) {
fmt.Printf("Register confirmed no existing username\n")
log.Printf("Register confirmed no existing username\n")
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Attempt to register conflicting username"})
return
@@ -64,7 +64,7 @@ func Register(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"Error hashing password": err.Error()})
return
} else {
fmt.Printf("Register generated hashed password value '%s' from '%s'\n", string(hashedPassword), input.Password)
log.Printf("Register generated hashed password value '%s' from '%s'\n", string(hashedPassword), input.Password)
}
u.Password = string(hashedPassword)
@@ -92,7 +92,7 @@ func Login(c *gin.Context) {
u.UserName = input.Username
u.Password = input.Password
fmt.Printf("Login checking username '%s' and password '%s'\n", u.UserName, u.Password)
log.Printf("Login checking username '%s' and password '%s'\n", u.UserName, u.Password)
token, err := models.LoginCheck(u.UserName, u.Password)

View File

@@ -3,7 +3,7 @@ package controllers
import (
"ccsecrets/models"
"ccsecrets/utils/token"
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
@@ -22,7 +22,7 @@ func RetrieveSecret(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
fmt.Printf("RetrieveSecret received JSON input '%v'\n", input)
log.Printf("RetrieveSecret received JSON input '%v'\n", input)
// Get the user and role id of the requestor
user_id, err := token.ExtractTokenID(c)
@@ -72,7 +72,7 @@ func RetrieveMultpleSecrets(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
fmt.Printf("StoreSecret received JSON input '%v'\n", input)
log.Printf("StoreSecret received JSON input '%v'\n", input)
// Get the user and role id of the requestor
user_id, err := token.ExtractTokenID(c)

View File

@@ -3,7 +3,7 @@ package controllers
import (
"ccsecrets/models"
"errors"
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
@@ -27,7 +27,7 @@ func StoreSecret(c *gin.Context) {
return
}
fmt.Printf("StoreSecret received JSON input '%v'\n", input)
log.Printf("StoreSecret received JSON input '%v'\n", input)
// Populate fields
s := models.Secret{}
@@ -55,7 +55,7 @@ func StoreSecret(c *gin.Context) {
}
if len(checkExists) > 0 {
fmt.Printf("StoreSecret not storing secret with '%d' already matching secrets.\n", len(checkExists))
log.Printf("StoreSecret not storing secret with '%d' already matching secrets.\n", len(checkExists))
c.JSON(http.StatusBadRequest, gin.H{"error": "StoreSecret attempting to store secret already defined. API calls for update/delete don't yet exist"})
return
}
@@ -86,7 +86,7 @@ func UpdateSecret(c *gin.Context) {
return
}
fmt.Printf("UpdateSecret received JSON input '%v'\n", input)
log.Printf("UpdateSecret received JSON input '%v'\n", input)
// Get the user and role id of the requestor
u, err := models.GetUserRoleFromToken(c)