Created
September 4, 2017 10:23
-
-
Save vuongngo/f770a06a865ec467622dfd9df3b542fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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