github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume3/section5/gopherface/common/datastore/datastore.go (about) 1 package datastore 2 3 import ( 4 "github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/models/socialmedia" 5 6 "github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/models" 7 ) 8 9 type Datastore interface { 10 CreateUser(user *models.User) error 11 GetUser(username string) (*models.User, error) 12 Close() 13 GetUserProfile(uuid string) (*models.UserProfile, error) 14 UpdateUserProfile(uuid, about, location, interests string) error 15 UpdateUserProfileImage(uuid, profileImagePath string) error 16 FindGophers(owner string, searchTerm string) ([]models.Gopher, error) 17 FriendsList(owner string) ([]models.Gopher, error) 18 FollowGopher(owner string, friend string) error 19 UnfollowGopher(owner string, friend string) error 20 SavePost(owner string, title string, body string, mood int) error 21 FetchPosts(owner string) ([]socialmedia.Post, error) 22 GetGopherProfile(username string) (*models.UserProfile, error) 23 } 24 25 const ( 26 MYSQL = iota 27 //MONGODB 28 //REDIS 29 ) 30 31 func NewDatastore(datastoreType int, dbConnectionString string) (Datastore, error) { 32 33 switch datastoreType { 34 case MYSQL: 35 return NewMySQLDatastore(dbConnectionString) 36 /* 37 case MONGODB: 38 return NewMongoDBDatastore(dbConnectionString) 39 case REDIS: 40 return NewRedisDatastore(dbConnectionString) 41 */ 42 } 43 44 return nil, nil 45 }