Refactor everything that's used all over into a common/ package and sync files from static/ into public/ so that public's not in the git.
This commit is contained in:
parent
d12817f4cc
commit
ec7298cce0
36 changed files with 112 additions and 902 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
|
||||
"zedshaw.games/webapp/data"
|
||||
. "zedshaw.games/webapp/common"
|
||||
)
|
||||
|
||||
var STORE *session.Store
|
||||
|
|
42
api/tools.go
42
api/tools.go
|
@ -1,42 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type Failure struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func IfErrNil(err error, c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
log.Output(10, err.Error())
|
||||
c.SendStatus(fiber.StatusInternalServerError)
|
||||
return c.JSON(Failure{err.Error()})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func ReceivePost[T any](c *fiber.Ctx) (*T, error) {
|
||||
var result *T
|
||||
result = new(T)
|
||||
|
||||
if err := c.BodyParser(result); err != nil {
|
||||
log.Println(err);
|
||||
return result, err
|
||||
}
|
||||
|
||||
var validate *validator.Validate
|
||||
validate = validator.New(validator.WithRequiredStructEnabled())
|
||||
|
||||
if err := validate.Struct(result); err != nil {
|
||||
validationErrors := err.(validator.ValidationErrors)
|
||||
log.Println(validationErrors)
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue