Skip to content

Instantly share code, notes, and snippets.

View ElegantSoft's full-sized avatar
🏠
Working from home

Abanoub Istfanous ElegantSoft

🏠
Working from home
View GitHub Profile
package main
import (
"encoding/json"
"fmt"
"github.com/joho/godotenv"
"log"
"net/http"
"time"
)
@ElegantSoft
ElegantSoft / validate_enum.go
Created September 23, 2020 01:17
Use enum validation in golang with gin with custom error messages
// user model
type User struct {
gorm.Model
Name string `json:"name" binding:"required" gorm:"not null:true"`
Phone string `json:"phone" binding:"required"`
Email string `json:"email" binding:"required,email" gorm:"not null:true"`
Password string `json:"password" binding:"required,min=8" gorm:"not null:true"`
Gender string `json:"gender" binding:"Enum=male_female" gorm:"type:gender;not null:true;default:male"` // add binding Enum=male_female
}