Documentation ¶
Index ¶
- Constants
- func GetMachineID() string
- type ComposePostService
- type ComposePostServiceImpl
- type Creator
- type FolloweeInfo
- type FollowerInfo
- type HomeTimelineService
- type HomeTimelineServiceImpl
- type LoginObj
- type Media
- type MediaService
- type MediaServiceImpl
- type Post
- type PostInfo
- type PostStorageService
- type PostStorageServiceImpl
- func (p *PostStorageServiceImpl) ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error)
- func (p *PostStorageServiceImpl) ReadPosts(ctx context.Context, reqID int64, postIDs []int64) ([]Post, error)
- func (p *PostStorageServiceImpl) StorePost(ctx context.Context, reqID int64, post Post) error
- type PostType
- type SocialGraphService
- type SocialGraphServiceImpl
- func (s *SocialGraphServiceImpl) Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
- func (s *SocialGraphServiceImpl) FollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error
- func (s *SocialGraphServiceImpl) GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error)
- func (s *SocialGraphServiceImpl) GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error)
- func (s *SocialGraphServiceImpl) InsertUser(ctx context.Context, reqID int64, userID int64) error
- func (s *SocialGraphServiceImpl) Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
- func (s *SocialGraphServiceImpl) UnfollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error
- type TextService
- type TextServiceImpl
- type URL
- type UniqueIdService
- type UniqueIdServiceImpl
- type UrlShortenService
- type UrlShortenServiceImpl
- type User
- type UserIDService
- type UserIDServiceImpl
- type UserInfo
- type UserMention
- type UserMentionService
- type UserMentionServiceImpl
- type UserPosts
- type UserService
- type UserServiceImpl
- func (u *UserServiceImpl) ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error)
- func (u *UserServiceImpl) ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error)
- func (u *UserServiceImpl) Login(ctx context.Context, reqID int64, username string, password string) (string, error)
- func (u *UserServiceImpl) RegisterUser(ctx context.Context, reqID int64, firstName string, lastName string, ...) error
- func (u *UserServiceImpl) RegisterUserWithId(ctx context.Context, reqID int64, firstName string, lastName string, ...) error
- type UserTimelineService
- type UserTimelineServiceImpl
- type Wrk2APIService
- type Wrk2APIServiceImpl
- func (w *Wrk2APIServiceImpl) ComposePost(ctx context.Context, userId int64, username string, post_type int64, ...) (int64, []int64, error)
- func (w *Wrk2APIServiceImpl) Follow(ctx context.Context, username string, followeeName string, userId int64, ...) error
- func (w *Wrk2APIServiceImpl) ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
- func (w *Wrk2APIServiceImpl) ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
- func (w *Wrk2APIServiceImpl) Register(ctx context.Context, firstName string, lastName string, username string, ...) error
- func (w *Wrk2APIServiceImpl) Unfollow(ctx context.Context, username string, followeeName string, userId int64, ...) error
Constants ¶
const ( POST int64 = iota REPOST REPLY DM )
Enums aren't supported atm. So just use integers instead.
Variables ¶
This section is empty.
Functions ¶
func GetMachineID ¶
func GetMachineID() string
From: https://gist.github.com/tsilvers/085c5f39430ced605d970094edf167ba
Types ¶
type ComposePostService ¶
type ComposePostService interface { // Compose a post from the provided arguments ComposePost(ctx context.Context, reqID int64, username string, userID int64, text string, mediaIDs []int64, mediaTypes []string, postType int64) (int64, []int64, error) }
The ComposePostService interface
func NewComposePostServiceImpl ¶
func NewComposePostServiceImpl(ctx context.Context, postStorageService PostStorageService, userTimelineService UserTimelineService, userService UserService, uniqueIDService UniqueIdService, mediaService MediaService, textService TextService, homeTimelineService HomeTimelineService) (ComposePostService, error)
Creates a ComposePostService instance that creates a post from the provided arguments and connects to the various internal services to store the newly created post and update the state.
type ComposePostServiceImpl ¶
type ComposePostServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of ComposePostService
type FolloweeInfo ¶
The format of a followee's info stored in the user info in the social-graph
type FollowerInfo ¶
The format of a follower's info stored in the user info in the social-graph
type HomeTimelineService ¶
type HomeTimelineService interface { // Reads the timeline of the user that has the id `userID`. // The return value is represented by the slice: post_ids[start:stop]. ReadHomeTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error) // Adds a new post to the home timeline of the following users: // (i) user with id `userID`, // (ii) all the followers of the user with `userID` // (iii) all the mentioned users in the post listed in the `userMentionIDs`. // The new post ID is placed at the nth position in the post ids array. // post_ids = append(post_ids, `postID`) WriteHomeTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64, userMentionIDs []int64) error }
The HomeTimelineService Interface The full Timeline of a user is represented as an array of post ids: post_ids[id_0 ,..., id_n].
func NewHomeTimelineServiceImpl ¶
func NewHomeTimelineServiceImpl(ctx context.Context, homeTimelineCache backend.Cache, postStorageService PostStorageService, socialGraphService SocialGraphService) (HomeTimelineService, error)
Creates a HomeTimelineService instance that maintains the home timelines for the various users.
type HomeTimelineServiceImpl ¶
type HomeTimelineServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of HomeTimelineService
type MediaService ¶
type MediaService interface { // Creates and returns a list of Media objects from the provided `mediaTypes` and `mediaIds` arguments. // Returns an error if the length of mediaTypes and mediaIds do not match. ComposeMedia(ctx context.Context, reqID int64, mediaTypes []string, mediaIds []int64) ([]Media, error) }
The MediaService interface
func NewMediaServiceImpl ¶
func NewMediaServiceImpl(ctx context.Context) (MediaService, error)
Creates a MediaService instance that creates media objects
type MediaServiceImpl ¶
type MediaServiceImpl struct{}
Implementation of MediaService
func (*MediaServiceImpl) ComposeMedia ¶
func (m *MediaServiceImpl) ComposeMedia(ctx context.Context, reqID int64, mediaTypes []string, mediaIds []int64) ([]Media, error)
Implements MediaService interface
type PostStorageService ¶
type PostStorageService interface { // Stores a new `post` in the relevant backends. StorePost(ctx context.Context, reqID int64, post Post) error // Returns the post with id `postID` // If no post with id `postID` exists in the database, an error is returned. ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error) // Returns a list of posts that have ids in the array `postIDs`. // No error is thrown if no post is found. ReadPosts(ctx context.Context, reqID int64, postIDs []int64) ([]Post, error) }
The PostStorageService interface
func NewPostStorageServiceImpl ¶
func NewPostStorageServiceImpl(ctx context.Context, postStorageCache backend.Cache, postStorageDB backend.NoSQLDatabase) (PostStorageService, error)
Creates a PostStorageService instance that manages the post backends.
type PostStorageServiceImpl ¶
type PostStorageServiceImpl struct { CacheHits int64 NumReqs int64 CacheMiss int64 // contains filtered or unexported fields }
Implementation of PostStorageService
func (*PostStorageServiceImpl) ReadPost ¶
func (p *PostStorageServiceImpl) ReadPost(ctx context.Context, reqID int64, postID int64) (Post, error)
Implements PostStorageService interface
type SocialGraphService ¶
type SocialGraphService interface { // Returns the user IDs of all the followers of the user with user id `userID`. // Returns an error if user with `userID` doesn't exist in database. GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error) // Returns the user IDs of all the followees of the user with user id `userID`. // Returns an error if user with `userID` doesn't exist in database. GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error) // Creates a follower-followee relationship between users with IDs `userID`-`followeeID`. Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error // Removes the follower-followee relationship between users with IDs `userID`-`followeeID`. Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error // Creates a follower-followee relationship between users with usernames `userUsername`-`followeeUsername`. FollowWithUsername(ctx context.Context, reqID int64, userUsername string, followeeUsername string) error // Removes the follower-followee relationship between users with usernames `userUsername`-`followeeUsername`. UnfollowWithUsername(ctx context.Context, reqID int64, userUsername string, followeeUsername string) error // Inserts a new user with `userID` in the database. InsertUser(ctx context.Context, reqID int64, userID int64) error }
The SocialGraphService interface
func NewSocialGraphServiceImpl ¶
func NewSocialGraphServiceImpl(ctx context.Context, socialGraphCache backend.Cache, socialGraphDB backend.NoSQLDatabase, userIDService UserIDService) (SocialGraphService, error)
Creates a SocialGraphService instance that maintains the social graph backends.
type SocialGraphServiceImpl ¶
type SocialGraphServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of SocialGraphService
func (*SocialGraphServiceImpl) Follow ¶
func (s *SocialGraphServiceImpl) Follow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
Implements SocialGraphService interface
func (*SocialGraphServiceImpl) FollowWithUsername ¶
func (s *SocialGraphServiceImpl) FollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error
Implements SocialGraphService interface
func (*SocialGraphServiceImpl) GetFollowees ¶
func (s *SocialGraphServiceImpl) GetFollowees(ctx context.Context, reqID int64, userID int64) ([]int64, error)
Implements SocialGraphService interface
func (*SocialGraphServiceImpl) GetFollowers ¶
func (s *SocialGraphServiceImpl) GetFollowers(ctx context.Context, reqID int64, userID int64) ([]int64, error)
Implements SocialGraphService interface
func (*SocialGraphServiceImpl) InsertUser ¶
Implements SocialGraphService interface
func (*SocialGraphServiceImpl) Unfollow ¶
func (s *SocialGraphServiceImpl) Unfollow(ctx context.Context, reqID int64, userID int64, followeeID int64) error
Implements SocialGraphService interface
func (*SocialGraphServiceImpl) UnfollowWithUsername ¶
func (s *SocialGraphServiceImpl) UnfollowWithUsername(ctx context.Context, reqID int64, username string, followee_name string) error
Implements SocialGraphService interface
type TextService ¶
type TextService interface { // Parses the raw `text` to return an edited text with the urls replaced with shortened urls, usermention objects to be stored with the post, and the url objects to be stored with the post. ComposeText(ctx context.Context, reqID int64, text string) (string, []UserMention, []URL, error) }
The TextService interface
func NewTextServiceImpl ¶
func NewTextServiceImpl(ctx context.Context, urlShortenService UrlShortenService, userMentionService UserMentionService) (TextService, error)
Creates a TextService instance for parsing texts in created posts.
type TextServiceImpl ¶
type TextServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of TextService
func (*TextServiceImpl) ComposeText ¶
func (t *TextServiceImpl) ComposeText(ctx context.Context, reqID int64, text string) (string, []UserMention, []URL, error)
Implements TextService interface
type UniqueIdService ¶
type UniqueIdService interface { // Returns a newly generated unique id to be used as a post's unique identifier. ComposeUniqueId(ctx context.Context, reqID int64, postType int64) (int64, error) }
The UniqueIdService interface
func NewUniqueIdServiceImpl ¶
func NewUniqueIdServiceImpl(ctx context.Context) (UniqueIdService, error)
Implements UniqueIdService interface
type UniqueIdServiceImpl ¶
type UniqueIdServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of UserTimelineService
func (*UniqueIdServiceImpl) ComposeUniqueId ¶
func (u *UniqueIdServiceImpl) ComposeUniqueId(ctx context.Context, reqID int64, postType int64) (int64, error)
Implements UniqueIdService interface
type UrlShortenService ¶
type UrlShortenService interface { // Converts raw `urls` into shortened urls to be used within the application. Returns the list of shortened urls. ComposeUrls(ctx context.Context, reqID int64, urls []string) ([]URL, error) // Converts the list of shortened urls into their extended forms. GetExtendedUrls(ctx context.Context, reqID int64, shortenedUrls []string) ([]string, error) }
The UrlShortenService interface
func NewUrlShortenServiceImpl ¶
func NewUrlShortenServiceImpl(ctx context.Context, urlShortenDB backend.NoSQLDatabase) (UrlShortenService, error)
Creates a UrlShortenService instance for converting raw urls to shortened urls and vice versa.
type UrlShortenServiceImpl ¶
type UrlShortenServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of UrlShortenService
func (*UrlShortenServiceImpl) ComposeUrls ¶
func (u *UrlShortenServiceImpl) ComposeUrls(ctx context.Context, reqID int64, urls []string) ([]URL, error)
Implements ComposeUrls interface
func (*UrlShortenServiceImpl) GetExtendedUrls ¶
func (u *UrlShortenServiceImpl) GetExtendedUrls(ctx context.Context, reqID int64, shortenedUrls []string) ([]string, error)
Implements UrlShortenService interface. Currently not implemented as the original DSB application doesn't implement this function either.
type User ¶
type User struct { UserID int64 FirstName string LastName string Username string PwdHashed string Salt string }
The format of a user stored in the user database
type UserIDService ¶
type UserIDService interface { // Returns the userID of the user associated with the `username`. // Returns an error if no user exists with the given `username`. GetUserId(ctx context.Context, reqID int64, username string) (int64, error) }
The UserIDService interface
func NewUserIDServiceImpl ¶
func NewUserIDServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase) (UserIDService, error)
Creates a UserIDService instance for looking up users with usernames.
type UserIDServiceImpl ¶
type UserIDServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of UserIDService
type UserInfo ¶
type UserInfo struct { UserID int64 Followers []FollowerInfo Followees []FolloweeInfo }
The format of a user's info stored in the social-graph
type UserMention ¶
The format of a usermention stored as part of a post
type UserMentionService ¶
type UserMentionService interface { // Composes UserMention objects to be stored in a post by converting raw usernames. // Returns an error if any name in the `usernames` array is not registered. ComposeUserMentions(ctx context.Context, reqID int64, usernames []string) ([]UserMention, error) }
The UserMentionService interface
func NewUserMentionServiceImpl ¶
func NewUserMentionServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase) (UserMentionService, error)
Creates a UserMentionService instance that is responsible for converting usernames to usermention objects
type UserMentionServiceImpl ¶
type UserMentionServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of UserMentionService
func (*UserMentionServiceImpl) ComposeUserMentions ¶
func (u *UserMentionServiceImpl) ComposeUserMentions(ctx context.Context, reqID int64, usernames []string) ([]UserMention, error)
Implements the UserMentionService interface
type UserService ¶
type UserService interface { // Logs in a user using the user's `username` and `password` // Returns an error if the username is not registered or if the provided password doesn't match the stored password. Login(ctx context.Context, reqID int64, username string, password string) (string, error) // Registers a new user with a given `userID`. // Returns an error if the `userID` is already taken. RegisterUserWithId(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string, userID int64) error // Registers a new user. A random `userID` is generated by the service. RegisterUser(ctx context.Context, reqID int64, firstName string, lastName string, username string, password string) error // Creates and returns a creator object to be included in a Post. The Creator object is created using the `userID`. ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error) // Creates and returns a creator object to be included in a Post. The service looks up the userID of the user with the given `username`. // Returns an error if the user with the given `username` is not registered. ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error) }
The UserService interface
func NewUserServiceImpl ¶
func NewUserServiceImpl(ctx context.Context, userCache backend.Cache, userDB backend.NoSQLDatabase, socialGraphService SocialGraphService, secret string) (UserService, error)
Implementation of UserService
type UserServiceImpl ¶
type UserServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of UserService
func (*UserServiceImpl) ComposeCreatorWithUserId ¶
func (u *UserServiceImpl) ComposeCreatorWithUserId(ctx context.Context, reqID int64, userID int64, username string) (Creator, error)
Implements UserService interface
func (*UserServiceImpl) ComposeCreatorWithUsername ¶
func (u *UserServiceImpl) ComposeCreatorWithUsername(ctx context.Context, reqID int64, username string) (Creator, error)
Implements UserService interface
func (*UserServiceImpl) Login ¶
func (u *UserServiceImpl) Login(ctx context.Context, reqID int64, username string, password string) (string, error)
Implements UserService interface
type UserTimelineService ¶
type UserTimelineService interface { // Reads the timeline of the user that has the id `userID`. // The return value is represented by the slice: post_ids[start:stop]. ReadUserTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error) // Adds a new post to the user timeline of the user that has the id `userID` // The new post ID is placed at the 0th position in the post ids array. // post_ids = []int64{`postID`, post_ids...) WriteUserTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64) error }
The UserTimelineService interface The full Timeline of a user is represented as an array of post ids: post_ids[id_0 ,..., id_n].
func NewUserTimelineServiceImpl ¶
func NewUserTimelineServiceImpl(ctx context.Context, userTimelineCache backend.Cache, userTimelineDB backend.NoSQLDatabase, postStorageService PostStorageService) (UserTimelineService, error)
Creates a UserTimelineService instance for managing the user timelines for the various users.
type UserTimelineServiceImpl ¶
type UserTimelineServiceImpl struct { CacheHits int64 CacheMiss int64 NumRequests int64 // contains filtered or unexported fields }
Implementation of UserTimelineService
func (*UserTimelineServiceImpl) ReadUserTimeline ¶
func (u *UserTimelineServiceImpl) ReadUserTimeline(ctx context.Context, reqID int64, userID int64, start int64, stop int64) ([]int64, error)
Implements UserTimelineService interface
func (*UserTimelineServiceImpl) WriteUserTimeline ¶
func (u *UserTimelineServiceImpl) WriteUserTimeline(ctx context.Context, reqID int64, postID int64, userID int64, timestamp int64) error
Implements UserTimelineService interface
type Wrk2APIService ¶
type Wrk2APIService interface { // Reads the home timeline of the user with `userId`. // Returns the list of posts[start, stop] from the timeline. ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error) // Reads the user timeline of the user with `userId`. // Returns the list of posts[start, stop] from the timeline. ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error) // Creates a Follow-Link between users `userId`-`followeeID`. // If the user ids are not provided, then it creates a follow-link between users `username`-`followeeName`. // Returns an error if no pairs are provided. Follow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error // Removes a Follow-Link between users `userId`-`followeeID`. // If the user ids are not provided, then it creates a follow-link between users `username`-`followeeName`. // Returns an error if no pairs are provided. Unfollow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error // Registers a new user with the given `userId`. Register(ctx context.Context, firstName string, lastName string, username string, password string, userId int64) error // Composes a new post give the provided arguments. // Returns the created post's ID and the ids of the mentioned users. ComposePost(ctx context.Context, userId int64, username string, post_type int64, text string, media_types []string, media_ids []int64) (int64, []int64, error) }
The Wrk2APIService (Frontend) interface
func NewWrk2APIServiceImpl ¶
func NewWrk2APIServiceImpl(ctx context.Context, userService UserService, composePostService ComposePostService, userTimelineService UserTimelineService, homeTimelineService HomeTimelineService, socialGraphService SocialGraphService) (Wrk2APIService, error)
Creates a Wrk2APIService instance to act as the gateway to internal services.
type Wrk2APIServiceImpl ¶
type Wrk2APIServiceImpl struct {
// contains filtered or unexported fields
}
Implementation of Wrk2APIService
func (*Wrk2APIServiceImpl) ComposePost ¶
func (w *Wrk2APIServiceImpl) ComposePost(ctx context.Context, userId int64, username string, post_type int64, text string, media_types []string, media_ids []int64) (int64, []int64, error)
Implements Wrk2APIService interface
func (*Wrk2APIServiceImpl) Follow ¶
func (w *Wrk2APIServiceImpl) Follow(ctx context.Context, username string, followeeName string, userId int64, followeeID int64) error
Implements Wrk2APIService interface
func (*Wrk2APIServiceImpl) ReadHomeTimeline ¶
func (w *Wrk2APIServiceImpl) ReadHomeTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
Implements Wrk2APIService interface
func (*Wrk2APIServiceImpl) ReadUserTimeline ¶
func (w *Wrk2APIServiceImpl) ReadUserTimeline(ctx context.Context, userId int64, start int64, stop int64) ([]int64, error)
Implements Wrk2APIService interface