Documentation ¶
Index ¶
- Constants
- Variables
- func ValidUsername(s string) bool
- type AlreadyExistsError
- type AuthOutput
- type Comment
- type Comments
- type GoneError
- type InvalidArgumentError
- type NotFoundError
- type Notification
- type Notifications
- type PermissionDeniedError
- type Post
- type Posts
- type PostsOpt
- type PostsOpts
- type ProvidedUser
- type Reaction
- type ReactionInput
- type SendMagicLink
- type Service
- func (svc *Service) AddWebPushSubscription(ctx context.Context, sub webpush.Subscription) error
- func (s *Service) AuthUser(ctx context.Context) (User, error)
- func (s *Service) AuthUserIDFromToken(token string) (string, error)
- func (s *Service) CommentStream(ctx context.Context, postID string) (<-chan Comment, error)
- func (s *Service) Comments(ctx context.Context, postID string, last uint64, before *string) (Comments, error)
- func (s *Service) CreateComment(ctx context.Context, postID string, content string) (Comment, error)
- func (s *Service) CreateTimelineItem(ctx context.Context, content string, spoilerOf *string, nsfw bool, ...) (TimelineItem, error)
- func (s *Service) DeleteComment(ctx context.Context, commentID string) error
- func (s *Service) DeletePost(ctx context.Context, postID string) error
- func (s *Service) DeleteTimelineItem(ctx context.Context, timelineItemID string) error
- func (s *Service) DevLogin(ctx context.Context, email string) (AuthOutput, error)
- func (s *Service) Followees(ctx context.Context, username string, first uint64, after *string) (UserProfiles, error)
- func (s *Service) Followers(ctx context.Context, username string, first uint64, after *string) (UserProfiles, error)
- func (s *Service) HasUnreadNotifications(ctx context.Context) (bool, error)
- func (svc *Service) LoginFromProvider(ctx context.Context, name string, providedUser ProvidedUser) (User, error)
- func (s *Service) MarkNotificationAsRead(ctx context.Context, notificationID string) error
- func (s *Service) MarkNotificationsAsRead(ctx context.Context) error
- func (s *Service) NotificationStream(ctx context.Context) (<-chan Notification, error)
- func (s *Service) Notifications(ctx context.Context, last uint64, before *string) (Notifications, error)
- func (s *Service) ParseRedirectURI(rawurl string) (*url.URL, error)
- func (s *Service) Post(ctx context.Context, postID string) (Post, error)
- func (s *Service) PostStream(ctx context.Context) (<-chan Post, error)
- func (s *Service) Posts(ctx context.Context, last uint64, before *string, opts ...PostsOpt) (Posts, error)
- func (s *Service) SendMagicLink(ctx context.Context, in SendMagicLink) error
- func (s *Service) Timeline(ctx context.Context, last uint64, before *string) (Timeline, error)
- func (s *Service) TimelineItemStream(ctx context.Context) (<-chan TimelineItem, error)
- func (s *Service) ToggleCommentReaction(ctx context.Context, commentID string, in ReactionInput) ([]Reaction, error)
- func (s *Service) ToggleFollow(ctx context.Context, username string) (ToggleFollowOutput, error)
- func (s *Service) TogglePostReaction(ctx context.Context, postID string, in ReactionInput) ([]Reaction, error)
- func (s *Service) TogglePostSubscription(ctx context.Context, postID string) (ToggleSubscriptionOutput, error)
- func (s *Service) Token(ctx context.Context) (TokenOutput, error)
- func (s *Service) UpdateAvatar(ctx context.Context, r io.ReadSeeker) (string, error)
- func (s *Service) UpdateComment(ctx context.Context, in UpdateComment) (UpdatedComment, error)
- func (s *Service) UpdateCover(ctx context.Context, r io.ReadSeeker) (string, error)
- func (s *Service) UpdatePost(ctx context.Context, postID string, params UpdatePost) (UpdatedPost, error)
- func (s *Service) UpdateUser(ctx context.Context, params UpdateUserParams) error
- func (s *Service) User(ctx context.Context, username string) (UserProfile, error)
- func (s *Service) Usernames(ctx context.Context, startingWith string, first uint64, after *string) (Usernames, error)
- func (s *Service) Users(ctx context.Context, search string, first uint64, after *string) (UserProfiles, error)
- func (s *Service) VerifyMagicLink(ctx context.Context, email, code string, username *string) (AuthOutput, error)
- type Timeline
- type TimelineItem
- type ToggleFollowOutput
- type ToggleSubscriptionOutput
- type TokenOutput
- type UnauthenticatedError
- type UnimplementedError
- type UpdateComment
- type UpdatePost
- type UpdateUserParams
- type UpdatedComment
- type UpdatedPost
- type User
- type UserProfile
- type UserProfiles
- type Usernames
Constants ¶
const ( MaxMediaItemBytes = 5 << 20 // 5MB MaxMediaBytes = 15 << 20 // 15MB )
const ( // MaxAvatarBytes to read. MaxAvatarBytes = 5 << 20 // 5MB // MaxCoverBytes to read. MaxCoverBytes = 20 << 20 // 20MB AvatarsBucket = "avatars" CoversBucket = "covers" )
const KeyAuthUserID = ctxkey("auth_user_id")
KeyAuthUserID to use in context.
const MediaBucket = "media"
Variables ¶
var ( // ErrInvalidRedirectURI denotes an invalid redirect URI. ErrInvalidRedirectURI = InvalidArgumentError("invalid redirect URI") // ErrUntrustedRedirectURI denotes an untrusted redirect URI. // That is an URI that is not in the same host as the nakama. ErrUntrustedRedirectURI = PermissionDeniedError("untrusted redirect URI") // ErrInvalidToken denotes an invalid token. ErrInvalidToken = InvalidArgumentError("invalid token") // ErrExpiredToken denotes that the token already expired. ErrExpiredToken = UnauthenticatedError("expired token") // ErrInvalidVerificationCode denotes an invalid verification code. ErrInvalidVerificationCode = InvalidArgumentError("invalid verification code") // ErrVerificationCodeNotFound denotes a not found verification code. ErrVerificationCodeNotFound = NotFoundError("verification code not found") )
var ( // ErrInvalidCommentID denotes an invalid comment ID; that is not uuid. ErrInvalidCommentID = InvalidArgumentError("invalid comment ID") // ErrCommentNotFound denotes a not found comment. ErrCommentNotFound = NotFoundError("comment not found") ErrUpdateCommentDenied = PermissionDeniedError("update comment denied") )
var ( // ErrInvalidPostID denotes an invalid post ID; that is not uuid. ErrInvalidPostID = InvalidArgumentError("invalid post ID") // ErrInvalidContent denotes an invalid content. ErrInvalidContent = InvalidArgumentError("invalid content") // ErrInvalidSpoiler denotes an invalid spoiler title. ErrInvalidSpoiler = InvalidArgumentError("invalid spoiler") // ErrPostNotFound denotes a not found post. ErrPostNotFound = NotFoundError("post not found") // ErrInvalidUpdatePostParams denotes invalid params to update a post, that is no params altogether. ErrInvalidUpdatePostParams = InvalidArgumentError("invalid update post params") // ErrInvalidCursor denotes an invalid cursor, that is not base64 encoded and has a key and timestamp separated by comma. ErrInvalidCursor = InvalidArgumentError("invalid cursor") // ErrInvalidReaction denotes an invalid reaction, that may by an invalid reaction type, or invalid reaction by itslef, // not a valid emoji, or invalid reaction image URL. ErrInvalidReaction = InvalidArgumentError("invalid reaction") ErrUpdatePostDenied = PermissionDeniedError("update post denied") )
var ( // ErrInvalidTimelineItemID denotes an invalid timeline item id; that is not uuid. ErrInvalidTimelineItemID = InvalidArgumentError("invalid timeline item ID") // ErrUnsupportedMediaItemFormat denotes an unsupported media item format. ErrUnsupportedMediaItemFormat = InvalidArgumentError("unsupported media item format") ErrMediaItemTooLarge = InvalidArgumentError("media item too large") ErrMediaTooLarge = InvalidArgumentError("media too large") )
var ( // ErrInvalidUserID denotes an invalid user id; that is not uuid. ErrInvalidUserID = InvalidArgumentError("invalid user ID") // ErrInvalidEmail denotes an invalid email address. ErrInvalidEmail = InvalidArgumentError("invalid email") // ErrInvalidUsername denotes an invalid username. ErrInvalidUsername = InvalidArgumentError("invalid username") // ErrEmailTaken denotes an email already taken. ErrEmailTaken = AlreadyExistsError("email taken") // ErrUsernameTaken denotes a username already taken. ErrUsernameTaken = AlreadyExistsError("username taken") // ErrUserNotFound denotes a not found user. ErrUserNotFound = NotFoundError("user not found") // ErrForbiddenFollow denotes a forbiden follow. Like following yourself. ErrForbiddenFollow = PermissionDeniedError("forbidden follow") // ErrUnsupportedAvatarFormat denotes an unsupported avatar image format. ErrUnsupportedAvatarFormat = InvalidArgumentError("unsupported avatar format") // ErrUnsupportedCoverFormat denotes an unsupported avatar image format. ErrUnsupportedCoverFormat = InvalidArgumentError("unsupported cover format") // ErrUserGone denotes that the user has already been deleted. ErrUserGone = GoneError("user gone") // ErrInvalidUpdateUserParams denotes invalid params to update a user, that is no params altogether. ErrInvalidUpdateUserParams = InvalidArgumentError("invalid update user params") // ErrInvalidUserBio denotes an invalid user bio. That is empty or it exceeds the max allowed characters (480). ErrInvalidUserBio = InvalidArgumentError("invalid user bio") // ErrInvalidUserWaifu denotes an invalid waifu name for an user. ErrInvalidUserWaifu = InvalidArgumentError("invalid user waifu") // ErrInvalidUserHusbando denotes an invalid husbando name for an user. ErrInvalidUserHusbando = InvalidArgumentError("invalid user husbando") )
var ErrAlreadyExists = errors.New("already exists")
var ErrGone = errors.New("gone")
var ErrInvalidArgument = errors.New("invalid argument")
var ErrInvalidNotificationID = InvalidArgumentError("invalid notification ID")
ErrInvalidNotificationID denotes an invalid notification id; that is not uuid.
var ErrNotFound = errors.New("not found")
var ErrPermissionDenied = errors.New("permission denied")
var ErrUnauthenticated = errors.New("unauthenticated")
ErrUnauthenticated denotes no authenticated user in context.
var ErrUnimplemented = errors.New("unimplemented")
var Schema string
Functions ¶
func ValidUsername ¶
Types ¶
type AlreadyExistsError ¶
type AlreadyExistsError string
func (AlreadyExistsError) Error ¶
func (e AlreadyExistsError) Error() string
func (AlreadyExistsError) Unwrap ¶
func (e AlreadyExistsError) Unwrap() error
type AuthOutput ¶
type AuthOutput struct { User User `json:"user"` Token string `json:"token"` ExpiresAt time.Time `json:"expiresAt"` }
AuthOutput response.
type Comment ¶
type Comment struct { ID string `json:"id"` UserID string `json:"-"` PostID string `json:"-"` Content string `json:"content"` Reactions []Reaction `json:"reactions"` CreatedAt time.Time `json:"createdAt"` User *User `json:"user,omitempty"` Mine bool `json:"mine"` }
Comment model.
type InvalidArgumentError ¶
type InvalidArgumentError string
func (InvalidArgumentError) Error ¶
func (e InvalidArgumentError) Error() string
func (InvalidArgumentError) Unwrap ¶
func (e InvalidArgumentError) Unwrap() error
type NotFoundError ¶
type NotFoundError string
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
func (NotFoundError) Unwrap ¶
func (e NotFoundError) Unwrap() error
type Notification ¶
type Notification struct { ID string `json:"id"` UserID string `json:"-"` Actors []string `json:"actors"` Type string `json:"type"` PostID *string `json:"postID,omitempty"` Read bool `json:"read"` IssuedAt time.Time `json:"issuedAt"` }
Notification model.
type Notifications ¶
type Notifications []Notification
func (Notifications) EndCursor ¶
func (pp Notifications) EndCursor() *string
type PermissionDeniedError ¶
type PermissionDeniedError string
func (PermissionDeniedError) Error ¶
func (e PermissionDeniedError) Error() string
func (PermissionDeniedError) Unwrap ¶
func (e PermissionDeniedError) Unwrap() error
type Post ¶
type Post struct { ID string `json:"id"` UserID string `json:"-"` Content string `json:"content"` SpoilerOf *string `json:"spoilerOf"` NSFW bool `json:"nsfw"` Reactions []Reaction `json:"reactions"` CommentsCount int `json:"commentsCount"` MediaURLs []string `json:"mediaURLs"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` User *User `json:"user,omitempty"` Mine bool `json:"mine"` Subscribed bool `json:"subscribed"` }
Post model.
type ProvidedUser ¶
type ReactionInput ¶
type SendMagicLink ¶
type Service ¶
type Service struct { Logger log.Logger DB *sql.DB Sender mailing.Sender Origin *url.URL TokenKey string PubSub pubsub.PubSub Store storage.Store AvatarURLPrefix string CoverURLPrefix string MediaURLPrefix string DisabledDevLogin bool AllowedOrigins []string VAPIDPrivateKey string VAPIDPublicKey string // contains filtered or unexported fields }
Service contains the core business logic separated from the transport layer. You can use it to back a REST, gRPC or GraphQL API. You must call RunBackgroundJobs afterward.
func (*Service) AddWebPushSubscription ¶
func (*Service) AuthUserIDFromToken ¶
AuthUserIDFromToken decodes the token into a user ID.
func (*Service) CommentStream ¶
CommentStream to receive comments in realtime.
func (*Service) Comments ¶
func (s *Service) Comments(ctx context.Context, postID string, last uint64, before *string) (Comments, error)
Comments from a post in descending order with backward pagination.
func (*Service) CreateComment ¶
func (s *Service) CreateComment(ctx context.Context, postID string, content string) (Comment, error)
CreateComment on a post.
func (*Service) CreateTimelineItem ¶
func (s *Service) CreateTimelineItem(ctx context.Context, content string, spoilerOf *string, nsfw bool, media []io.ReadSeeker) (TimelineItem, error)
CreateTimelineItem publishes a post to the user timeline and fan-outs it to his followers.
func (*Service) DeleteComment ¶
func (*Service) DeleteTimelineItem ¶
DeleteTimelineItem from the auth user timeline.
func (*Service) DevLogin ¶
DevLogin is a login for development purposes only. TODO: disable dev login on production.
func (*Service) Followees ¶
func (s *Service) Followees(ctx context.Context, username string, first uint64, after *string) (UserProfiles, error)
Followees in ascending order with forward pagination.
func (*Service) Followers ¶
func (s *Service) Followers(ctx context.Context, username string, first uint64, after *string) (UserProfiles, error)
Followers in ascending order with forward pagination.
func (*Service) HasUnreadNotifications ¶
HasUnreadNotifications checks if the authenticated user has any unread notification.
func (*Service) LoginFromProvider ¶
func (*Service) MarkNotificationAsRead ¶
MarkNotificationAsRead sets a notification from the authenticated user as read.
func (*Service) MarkNotificationsAsRead ¶
MarkNotificationsAsRead sets all notification from the authenticated user as read.
func (*Service) NotificationStream ¶
func (s *Service) NotificationStream(ctx context.Context) (<-chan Notification, error)
NotificationStream to receive notifications in realtime.
func (*Service) Notifications ¶
func (s *Service) Notifications(ctx context.Context, last uint64, before *string) (Notifications, error)
Notifications from the authenticated user in descending order with backward pagination.
func (*Service) ParseRedirectURI ¶
ParseRedirectURI the given redirect URI and validates it.
func (*Service) PostStream ¶
PostStream to receive posts in realtime.
func (*Service) Posts ¶
func (s *Service) Posts(ctx context.Context, last uint64, before *string, opts ...PostsOpt) (Posts, error)
Posts in descending order and with backward pagination. They can be filtered from a specific user by using `PostsFromUser` option in this late case, user field won't be populated. They can also be filtered by tag using `PostsTagged`.
func (*Service) SendMagicLink ¶
func (s *Service) SendMagicLink(ctx context.Context, in SendMagicLink) error
SendMagicLink to login without passwords. Or to update and verify a new email address. A second endpoint GET /api/verify_magic_link?email&code&redirect_uri must exist.
func (*Service) Timeline ¶
Timeline of the authenticated user in descending order and with backward pagination.
func (*Service) TimelineItemStream ¶
func (s *Service) TimelineItemStream(ctx context.Context) (<-chan TimelineItem, error)
TimelineItemStream to receive timeline items in realtime.
func (*Service) ToggleCommentReaction ¶
func (*Service) ToggleFollow ¶
ToggleFollow between two users.
func (*Service) TogglePostReaction ¶
func (*Service) TogglePostSubscription ¶
func (s *Service) TogglePostSubscription(ctx context.Context, postID string) (ToggleSubscriptionOutput, error)
TogglePostSubscription so you can stop receiving notifications from a thread.
func (*Service) Token ¶
func (s *Service) Token(ctx context.Context) (TokenOutput, error)
Token to authenticate requests.
func (*Service) UpdateAvatar ¶
UpdateAvatar of the authenticated user returning the new avatar URL. Please limit the reader before hand using MaxAvatarBytes.
func (*Service) UpdateComment ¶
func (s *Service) UpdateComment(ctx context.Context, in UpdateComment) (UpdatedComment, error)
func (*Service) UpdateCover ¶
UpdateCover of the authenticated user returning the new cover URL. Please limit the reader before hand using MaxCoverBytes.
func (*Service) UpdatePost ¶
func (s *Service) UpdatePost(ctx context.Context, postID string, params UpdatePost) (UpdatedPost, error)
func (*Service) UpdateUser ¶
func (s *Service) UpdateUser(ctx context.Context, params UpdateUserParams) error
func (*Service) Usernames ¶
func (s *Service) Usernames(ctx context.Context, startingWith string, first uint64, after *string) (Usernames, error)
Usernames to autocomplete a mention box or something.
func (*Service) Users ¶
func (s *Service) Users(ctx context.Context, search string, first uint64, after *string) (UserProfiles, error)
Users in ascending order with forward pagination and filtered by username.
func (*Service) VerifyMagicLink ¶
func (s *Service) VerifyMagicLink(ctx context.Context, email, code string, username *string) (AuthOutput, error)
VerifyMagicLink checks whether the given email and verification code exists and issues a new auth token. If the user does not exists, it can create a new one with the given username.
type Timeline ¶
type Timeline []TimelineItem
type TimelineItem ¶
type TimelineItem struct { ID string `json:"timelineItemID"` UserID string `json:"-"` PostID string `json:"-"` *Post }
TimelineItem model.
type ToggleFollowOutput ¶
type ToggleFollowOutput struct { Following bool `json:"following"` FollowersCount int `json:"followersCount"` }
ToggleFollowOutput response.
type ToggleSubscriptionOutput ¶
type ToggleSubscriptionOutput struct {
Subscribed bool `json:"subscribed"`
}
ToggleSubscriptionOutput response.
type TokenOutput ¶
TokenOutput response.
type UnauthenticatedError ¶
type UnauthenticatedError string
func (UnauthenticatedError) Error ¶
func (e UnauthenticatedError) Error() string
func (UnauthenticatedError) Unwrap ¶
func (e UnauthenticatedError) Unwrap() error
type UnimplementedError ¶
type UnimplementedError string
func (UnimplementedError) Error ¶
func (e UnimplementedError) Error() string
func (UnimplementedError) Unwrap ¶
func (e UnimplementedError) Unwrap() error
type UpdateComment ¶
type UpdatePost ¶
type UpdatePost struct { Content *string `json:"content"` SpoilerOf *string `json:"spoilerOf"` NSFW *bool `json:"nsfw"` }
func (UpdatePost) Empty ¶
func (params UpdatePost) Empty() bool
type UpdateUserParams ¶
type UpdatedComment ¶
type UpdatedComment struct {
Content string `json:"content"`
}
type UpdatedPost ¶
type User ¶
type User struct { ID string `json:"id,omitempty"` Username string `json:"username"` AvatarURL *string `json:"avatarURL"` }
User model.
type UserProfile ¶
type UserProfile struct { User Email string `json:"email,omitempty"` CoverURL *string `json:"coverURL"` Bio *string `json:"bio"` Waifu *string `json:"waifu"` Husbando *string `json:"husbando"` FollowersCount int `json:"followersCount"` FolloweesCount int `json:"followeesCount"` Me bool `json:"me"` Following bool `json:"following"` Followeed bool `json:"followeed"` }
UserProfile model.
type UserProfiles ¶
type UserProfiles []UserProfile
func (UserProfiles) EndCursor ¶
func (uu UserProfiles) EndCursor() *string