Skip to content

Instantly share code, notes, and snippets.

@vuongngo
Created September 4, 2017 10:23
Show Gist options
  • Save vuongngo/f770a06a865ec467622dfd9df3b542fc to your computer and use it in GitHub Desktop.
Save vuongngo/f770a06a865ec467622dfd9df3b542fc to your computer and use it in GitHub Desktop.
package model
import (
"net/http"
"time"
"github.com/mholt/binding"
"gopkg.in/mgo.v2/bson"
)
// Data model for job
type Job struct {
ID string `bson:"_id" json:"_id" val_id:"required"`
Title string `bson:"title" json:"title" valid:"required"`
Description string `bson:"description" json:"description" valid:"required"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt" valid:"required"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt" valid:"required"`
}
// Request mapper and validation
type JobReq struct {
Title string `json:"title" xml:"title" form:"title" valid:"required"`
Description string `json:"description" xml:"description" form:"description" valid:"required"`
}
func (l *JobReq) FieldMap(r *http.Request) binding.FieldMap {
return binding.FieldMap{
&l.Title: "title",
&l.Description: "description",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment