Last active
March 14, 2017 08:43
-
-
Save eamonnmcevoy/eab6c0d6070d63a3576a91ee38cd0f70 to your computer and use it in GitHub Desktop.
v1
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 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