Project layout design influenced by standard go project layout
-
install depedency
make tidy # or go mod tidy
-
copy environment
make config #or cp .env.example .env
-
generate key
make key
-
run dev mode
make serve
-
build
make build
-
run test
make gotest
-
make migration
make migration table="name_of_table"
-
run migration
make migrate-up
- unique
type v struct {
Name string `validate:"unique=table_name:column_name"`
}
// ecample
type v struct {
Name string `validate:"unique=users:name"`
}
- unique with ignore
type v struct {
Name string `validate:"unique=table_name:column_name:ignore_with_field_name"`
ID string `validate:"required"`
}
// example
type v struct {
Name string `validate:"unique=users:name:ID"`
ID string `validate:"required" json:"id"`
}
- file validation
type FileHandler struct {
File multipart.File `validate:"required,filetype=image/png image/jpeg image/jpg"`
}
fs := FileHandler{}
f, err := ctx.FormFile("file")
if err == nil {
// send file into FileHandler struct to validate
fs.File, err = f.Open()
if err != nil {
return err
}
}
// validate with custom validation from go-playground/validator
val, err := request.Validation(&fs)