Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f9a63e7fce
|
@ -16,18 +16,14 @@ func CreateManufacturer(c *gin.Context, manufacturer database.Manufacturer) {
|
|||
validate := validators.Validate
|
||||
response := message.Response{Status: 200}
|
||||
|
||||
err := validate.Struct(manufacturer)
|
||||
|
||||
if err != nil {
|
||||
if err := validate.Struct(manufacturer); err != nil {
|
||||
response.Error = libs.GetValidationErrors(err.(validator.ValidationErrors))
|
||||
response.Status = 400
|
||||
message.SendResponse(c, response)
|
||||
return
|
||||
}
|
||||
|
||||
err = db.Create(&manufacturer).Error
|
||||
|
||||
if err != nil {
|
||||
if err := db.Create(&manufacturer).Error; err != nil {
|
||||
log.Println(err.Error())
|
||||
response.Error = gin.H{
|
||||
"error": err.Error(),
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package controllers
|
||||
|
||||
// Пример генератора токена
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func tokenGenerator() string {
|
||||
b := make([]byte, 4)
|
||||
rand.Read(b)
|
||||
return fmt.Sprintf("%x", b)
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := tokenGenerator()
|
||||
fmt.Println(a)
|
||||
}
|
|
@ -21,4 +21,5 @@ type User struct {
|
|||
Email string
|
||||
Password string
|
||||
Products []*Product `gorm:"many2many:user_products;"`
|
||||
Token string `gorm:"many2many:user_token;"`
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -4,6 +4,7 @@ go 1.22.3
|
|||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/go-playground/validator/v10 v10.20.0
|
||||
gorm.io/driver/postgres v1.5.7
|
||||
gorm.io/gorm v1.25.10
|
||||
)
|
||||
|
@ -17,7 +18,6 @@ require (
|
|||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
|
|
Loading…
Reference in New Issue