Skip to content

yaza-putu/golang-fiber-starter-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Starter API With Mongo

golang

Project layout design influenced by standard go project layout

Note : Be sure to rename the name of module before beginning the project.

How to start

  • 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

Validation

  • 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)

About

Golang starter API with fiber,mongdb

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published