This file contains hidden or 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 root | |
| type User struct { | |
| Id string `json:"id"` | |
| Username string `json:"username"` | |
| Password string `json:"password"` | |
| } | |
| type UserService interface { | |
| CreateUser(u *User) error |
This file contains hidden or 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 root | |
| type User struct { | |
| Id string `json:"id"` | |
| Username string `json:"username"` | |
| Password string `json:"password"` | |
| } | |
| type UserService interface { | |
| CreateUser(u *User) error |
This file contains hidden or 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 ( | |
| "gopkg.in/mgo.v2" | |
| ) | |
| type Session struct { | |
| session *mgo.Session | |
| } |
This file contains hidden or 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 ( | |
| "gopkg.in/mgo.v2" | |
| "gopkg.in/mgo.v2/bson" | |
| "go_rest_api/pkg" | |
| ) | |
| type UserService struct { | |
| collection *mgo.Collection |
This file contains hidden or 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"` |
This file contains hidden or 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 config | |
| import ( | |
| "os" | |
| "fmt" | |
| "encoding/json" | |
| "path/filepath" | |
| "go_rest_api/pkg" | |
| ) |
This file contains hidden or 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 root | |
| type MongoConfig struct { | |
| Ip string `json:"ip"` | |
| DbName string `json:"dbName"` | |
| } | |
| type ServerConfig struct { | |
| Port string `json:"port"` | |
| } |
This file contains hidden or 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
| func(p *UserService) Create(u *root.User) error { | |
| user := newUserModel(u) | |
| return p.collection.Insert(&user) | |
| } | |
| func(p *UserService) GetByUsername(username string) (*root.User,error) { | |
| model := userModel{} | |
| err := p.collection.Find(bson.M{"username": username}).One(&model) | |
| return model.toRootUser(), err | |
| } |
This file contains hidden or 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_test | |
| import ( | |
| "log" | |
| "testing" | |
| "go_rest_api/pkg" | |
| "go_rest_api/pkg/mongo" | |
| ) | |
This file contains hidden or 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 ( | |
| "gopkg.in/mgo.v2" | |
| ) | |
| type Session struct { | |
| session *mgo.Session | |
| } |
OlderNewer