Skip to content

Instantly share code, notes, and snippets.

@eamonnmcevoy
Last active March 14, 2017 08:43
Show Gist options
  • Save eamonnmcevoy/eab6c0d6070d63a3576a91ee38cd0f70 to your computer and use it in GitHub Desktop.
Save eamonnmcevoy/eab6c0d6070d63a3576a91ee38cd0f70 to your computer and use it in GitHub Desktop.
v1
package mongo
import (
"go_rest_api/pkg"
"gopkg.in/mgo.v2/bson"
"gopkg.in/mgo.v2"
)
type userModel struct {
Id bson.ObjectId `bson:"_id,omitempty"`
Username string
Password string
}
func userModelIndex() mgo.Index {
return mgo.Index{
Key: []string{"username"},
Unique: true,
DropDups: true,
Background: true,
Sparse: true,
}
}
func newUserModel(u *root.User) *userModel {
return &userModel{
Username: u.Username,
Password: u.Password }
}
func(u *userModel) toRootUser() *root.User {
return &root.User{
Id: u.Id.Hex(),
Username: u.Username,
Password: u.Password }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment