Documentation ¶
Index ¶
- Constants
- Variables
- func ValidPlainPassword(pass string, ev *ErrValidation)
- func ValidPlainPasswordWithKey(pass string, ev *ErrValidation, errKey string)
- func ValidateAuthenticationToken(token string, ev *ErrValidation)
- func ValidateEmail(email string, ev *ErrValidation)
- func ValidateFilters(ev *ErrValidation, f *Filter)
- func ValidateMessageBody(body string, ev *ErrValidation)
- func ValidateMessageRcvrID(id string, ev *ErrValidation)
- func ValidateName(name string, ev *ErrValidation)
- func ValidateOTP(otp string, ev *ErrValidation)
- type Conversation
- type ConversationRepository
- type ConversationService
- type ErrValidation
- type Filter
- type LatestMsgBody
- type Message
- type MessageRepository
- type MessageSent
- type MessageService
- type Metadata
- type MsgChan
- type MsgOperation
- type Token
- type TokenRepository
- type TokenService
- type User
- type UserAuth
- type UserRegister
- type UserRepository
- type UserService
- type UserUpdate
Constants ¶
View Source
const ( ScopeActivation = "activation" ScopeAuthentication = "authentication" ScopeActivationTTL = 15 * time.Minute ScopeAuthenticationTTL = 7 * 24 * time.Hour )
Variables ¶
View Source
var ( ErrDuplicateEmail = errors.New("duplicate email") ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") ErrAlreadyActive = errors.New("user already active") ErrInactive = errors.New("user inactive") )
View Source
var ( RgxEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") AnonymousUser = &User{} )
View Source
var (
RgxOtp = regexp.MustCompile("^[0-9]{6}$")
)
Functions ¶
func ValidPlainPassword ¶
func ValidPlainPassword(pass string, ev *ErrValidation)
func ValidPlainPasswordWithKey ¶
func ValidPlainPasswordWithKey(pass string, ev *ErrValidation, errKey string)
func ValidateAuthenticationToken ¶
func ValidateAuthenticationToken(token string, ev *ErrValidation)
func ValidateEmail ¶
func ValidateEmail(email string, ev *ErrValidation)
func ValidateFilters ¶
func ValidateFilters(ev *ErrValidation, f *Filter)
func ValidateMessageBody ¶
func ValidateMessageBody(body string, ev *ErrValidation)
func ValidateMessageRcvrID ¶
func ValidateMessageRcvrID(id string, ev *ErrValidation)
func ValidateName ¶
func ValidateName(name string, ev *ErrValidation)
func ValidateOTP ¶
func ValidateOTP(otp string, ev *ErrValidation)
Types ¶
type Conversation ¶
type Conversation struct { SenderID string `json:"-" db:"sender_id"` ReceiverID string `json:"-" db:"receiver_id"` // Below given attributes will only be used on TUI (frontend side) UserID string `json:"userID" db:"user_id"` Username string `json:"username" db:"username"` UserEmail string `json:"userEmail" db:"user_email"` // status of user other than the currently logged-in user, can be either sender or receiver LastOnline *time.Time `json:"lastOnline" db:"last_online"` // latest msg to display under user's name in TUI, only used on frontend side LatestMsg *string `json:"-"` LatestMsgSentAt *time.Time `json:"-"` }
type ConversationRepository ¶
type ConversationService ¶
type ErrValidation ¶
func NewErrValidation ¶
func NewErrValidation() *ErrValidation
func (*ErrValidation) AddError ¶
func (e *ErrValidation) AddError(field, message string)
func (ErrValidation) Error ¶
func (ErrValidation) Error() string
implements error interface, so unwrap the error to get the validation errors
func (*ErrValidation) Evaluate ¶
func (e *ErrValidation) Evaluate(ok bool, field, message string)
func (*ErrValidation) HasErrors ¶
func (e *ErrValidation) HasErrors() bool
type LatestMsgBody ¶
type Message ¶
type Message struct { ID string `json:"id,omitempty"` SenderID string `json:"senderID,omitempty" db:"sender_id"` ReceiverID string `json:"receiverID,omitempty" db:"receiver_id"` Body string `json:"body,omitempty"` SentAt *time.Time `json:"sent_at,omitempty" db:"sent_at"` DeliveredAt *time.Time `json:"delivered_at,omitempty" db:"delivered_at"` ReadAt *time.Time `json:"read_at,omitempty" db:"read_at"` Version int `json:"-"` Operation MsgOperation `json:"operation" db:"operation"` }
type MessageRepository ¶
type MessageRepository interface { GetByID(ctx context.Context, id string, op MsgOperation) (*Message, error) GetUnDeliveredMessages(ctx context.Context, rcvrID string, op MsgOperation, c MsgChan) error InsertMessage(ctx context.Context, m *Message) error DeleteMessage(ctx context.Context, mID string) error }
type MessageSent ¶
type MessageSent struct { ID *string `json:"id"` ReceiverID string `json:"receiverID"` Body *string `json:"body"` SentAt *time.Time `json:"sent_at"` DeliveredAt *time.Time `json:"delivered_at"` ReadAt *time.Time `json:"read_at"` Operation MsgOperation `json:"operation"` }
func (MessageSent) ValidateMessageSent ¶
func (m MessageSent) ValidateMessageSent() *ErrValidation
TODO: Update this logic
type MessageService ¶
type Metadata ¶
type Metadata struct { CurrentPage int `json:"currentPage,omitempty"` PageSize int `json:"pageSize,omitempty"` FirstPage int `json:"firstPage,omitempty"` LastPage int `json:"lastPage,omitempty"` TotalRecords int `json:"totalRecords,omitempty"` }
func CalculateMetadata ¶
type MsgOperation ¶
type MsgOperation int
const ( // CreateMsg indicates the sender has sent a new msg CreateMsg MsgOperation = iota // DeliveredMsg indicates the receiver has received the msg DeliveredMsg // DeliveredConfirmMsg indicates the sender's acknowledgment for the msg delivery. // not to be persisted DeliveredConfirmMsg // ReadMsg indicates the receiver has read the msg ReadMsg // ReadConfirmMsg indicates the sender's acknowledgment, for the msg seen. // not to be persisted ReadConfirmMsg // DeleteMsg indicates the sender has deleted this msg DeleteMsg // DeleteConfirmMsg indicates the receiver's acknowledgment of the deleted message; // the receiving side will delete the msg, before sending this confirmation. // not to be persisted DeleteConfirmMsg // OnlineMsg indicates the user is online; a msg with this OP must not be persisted OnlineMsg // OfflineMsg indicates the user is offline; a msg with this OP must not be persisted OfflineMsg // TypingMsg indicates the user is typing; a msg with this OP must not be persisted TypingMsg // SyncConvosMsg tells the users to re-fetch their conversations from the server // not to be persisted, as we only want to send this for conversations' online users // offline ones will fetch from the server, when the TUI starts SyncConvosMsg )
type TokenRepository ¶
type TokenService ¶
type User ¶
type User struct { ID string `json:"id"` Name string `json:"name"` Email string `json:"email"` Password []byte `json:"-"` Activated bool `json:"-"` LastOnline *time.Time `json:"lastOnline,omitempty" db:"last_online"` CreatedAt time.Time `json:"createdAt" db:"created_at"` Version int `json:"-"` // Websocket related Messages MsgChan `json:"-"` CloseSlow func() `json:"-"` }
func (*User) IsAnonymousUser ¶
type UserRegister ¶
type UserRepository ¶
type UserRepository interface { RegisterUser(ctx context.Context, u *User) (string, error) ExistsUser(ctx context.Context, email string) (bool, error) GetByUniqueField(ctx context.Context, fieldName, fieldValue string) (*User, error) UpdateUser(ctx context.Context, u *User) error GetForToken(ctx context.Context, scope string, hash []byte) (*User, error) ActivateUser(ctx context.Context, user *User) error GetByQuery(ctx context.Context, paramName string, paramValue string, filter Filter) ([]*User, *Metadata, error) SetOnlineUsersLastSeen(ctx context.Context, t time.Time) error }
type UserService ¶
type UserService interface { RegisterUser(ctx context.Context, u *UserRegister) (string, error) ExistsUser(ctx context.Context, email string) (bool, error) GetByUniqueField(ctx context.Context, fieldValue string) (*User, error) UpdateUser(ctx context.Context, u *UserUpdate) error UpdateUserOnlineStatus(ctx context.Context, usr *User, online bool) error GetForToken(ctx context.Context, scope string, plainToken string) (*User, error) ActivateUser(ctx context.Context, user *User) error AuthenticateUser(ctx context.Context, u *UserAuth) (string, error) GetByQuery(ctx context.Context, queryParam string, filter Filter) ([]*User, *Metadata, error) SetOnlineUsersLastSeen(ctx context.Context, t time.Time) error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.