Documentation ¶
Overview ¶
File for the generation of random objects, suitable for testing needs
Index ¶
- Variables
- func GetRandBool() bool
- func GetRandChannelName() string
- func GetRandPassword() string
- func GetRandUsername() string
- func RandString(length int) string
- func RandStringWithCharset(length int, charset string) string
- type AccordClient
- func (c *AccordClient) AuthClient() *AuthClient
- func (c *AccordClient) Connect(addr string) error
- func (c *AccordClient) CreateChannel(name string, isPublic bool) (uint64, error)
- func (c *AccordClient) CreateUser(username string, password string) error
- func (c *AccordClient) GetChannel(channelID uint64) error
- func (c *AccordClient) GetChannels() error
- func (c *AccordClient) Login(username string, password string) error
- func (c *AccordClient) RemoveChannel(channelID uint64) error
- func (c *AccordClient) Send(msg *ChannelStreamRequest) error
- func (c *AccordClient) Subscribe(channelID uint64) (*StreamResponseCommunication, error)
- type AccordServer
- func (s *AccordServer) AddChannel(ctx context.Context, req *pb.AddChannelRequest) (*pb.AddChannelResponse, error)
- func (s *AccordServer) ChannelStream(srv pb.Chat_ChannelStreamServer) error
- func (s *AccordServer) GetChannel(ctx context.Context, req *pb.GetChannelRequest) (*pb.GetChannelResponse, error)
- func (s *AccordServer) GetChannels(ctx context.Context, req *pb.GetChannelsRequest) (*pb.GetChannelsResponse, error)
- func (s *AccordServer) Listen(serv_addr string) (string, error)
- func (s *AccordServer) LoadChannels() error
- func (s *AccordServer) LoadUsers() error
- func (s *AccordServer) RemoveChannel(_ context.Context, req *pb.RemoveChannelRequest) (*pb.RemoveChannelResponse, error)
- func (s *AccordServer) Start()
- type AuthClient
- type AuthServer
- func (s *AuthServer) CreateUser(_ context.Context, req *pb.CreateUserRequest) (*pb.CreateUserResponse, error)
- func (s *AuthServer) GetUser(username string) *User
- func (s *AuthServer) JWTManager() *JWTManager
- func (s *AuthServer) Login(_ context.Context, req *pb.LoginRequest) (*pb.LoginResponse, error)
- func (s *AuthServer) Logout(_ context.Context, req *pb.LogoutRequest) (*pb.LogoutResponse, error)
- type ChannelConfigMessage
- type ChannelStreamRequest
- type ChannelStreamRequestType
- type ChannelStreamResponse
- type ChannelStreamResponseType
- type ClientAuthInterceptor
- type ClientChannel
- type DeleteMessageUserChannelStreamRequest
- type DeleteMessageUserChannelStreamResponse
- type EditMessageUserChannelStreamRequest
- type JWTManager
- type Message
- type NameChannelConfigMessage
- type NewAndUpdateMessageUserChannelStreamResponse
- type NewMessageUserChannelStreamRequest
- type Permission
- type PinChannelConfigMessage
- type Role
- type RoleChannelConfigMessage
- type ServerAuthInterceptor
- type ServerChannel
- type StreamRequestCommunication
- type StreamResponseCommunication
- type User
- type UserChannelStreamRequest
- type UserChannelStreamResponse
- func (m *UserChannelStreamResponse) GetDeleteUserMsg() *DeleteMessageUserChannelStreamResponse
- func (m *UserChannelStreamResponse) GetMessageID() uint64
- func (m *UserChannelStreamResponse) GetNewAndUpdateUserMsg() *NewAndUpdateMessageUserChannelStreamResponse
- func (m *UserChannelStreamResponse) GetUserMsg() isUserChannelStreamResponseUserMsg
- type UserClaims
Constants ¶
This section is empty.
Variables ¶
var AccordToPBPermissions = map[Permission]pb.Permission{ UnknownPermission: pb.Permission_UNKNOWN_PERMISSION, ReadPermission: pb.Permission_READ, WritePermission: pb.Permission_WRITE, DeletePermission: pb.Permission_DELETE, ModifyPermission: pb.Permission_MODIFY, KickPermission: pb.Permission_KICK, BanPermission: pb.Permission_BAN, AssignRolePermission: pb.Permission_ASSIGN_ROLE, RemoveChannelPermission: pb.Permission_REMOVE_CHANNEL, }
AccordToPBPermissions is a mapping from objects of "Permission" type of this package to the objects from "pb" package.
var AccordToPBRoles = map[Role]pb.Role{ UnknownRole: pb.Role_UNKNOWN_ROLE, SubscriberRole: pb.Role_SUBSCRIBER, MemberRole: pb.Role_MEMBER, AdminRole: pb.Role_ADMIN, SuperadminRole: pb.Role_SUPERADMIN, }
var PBToAccordRoles = map[pb.Role]Role{ pb.Role_UNKNOWN_ROLE: UnknownRole, pb.Role_SUBSCRIBER: SubscriberRole, pb.Role_MEMBER: MemberRole, pb.Role_ADMIN: AdminRole, pb.Role_SUPERADMIN: SuperadminRole, }
Functions ¶
func GetRandBool ¶
func GetRandBool() bool
func GetRandChannelName ¶
func GetRandChannelName() string
func GetRandPassword ¶
func GetRandPassword() string
func GetRandUsername ¶
func GetRandUsername() string
func RandString ¶
func RandStringWithCharset ¶
Types ¶
type AccordClient ¶
type AccordClient struct { pb.ChatClient Username string ServerID uint64 Channels map[uint64]*ClientChannel // contains filtered or unexported fields }
func NewAccordClient ¶
func NewAccordClient(serverID uint64) *AccordClient
func (*AccordClient) AuthClient ¶
func (c *AccordClient) AuthClient() *AuthClient
func (*AccordClient) Connect ¶
func (c *AccordClient) Connect(addr string) error
func (*AccordClient) CreateChannel ¶
func (c *AccordClient) CreateChannel(name string, isPublic bool) (uint64, error)
CreateChannel sends the request to create new channel.
func (*AccordClient) CreateUser ¶
func (c *AccordClient) CreateUser(username string, password string) error
func (*AccordClient) GetChannel ¶
func (c *AccordClient) GetChannel(channelID uint64) error
func (*AccordClient) GetChannels ¶
func (c *AccordClient) GetChannels() error
func (*AccordClient) RemoveChannel ¶
func (c *AccordClient) RemoveChannel(channelID uint64) error
RemoveChannel permanently deletes the channel and all of its data.
func (*AccordClient) Send ¶
func (c *AccordClient) Send(msg *ChannelStreamRequest) error
func (*AccordClient) Subscribe ¶
func (c *AccordClient) Subscribe(channelID uint64) (*StreamResponseCommunication, error)
Subscribe returns the channel, which will send all the updates about the channel.
type AccordServer ¶
type AccordServer struct {
// contains filtered or unexported fields
}
func NewAccordServer ¶
func NewAccordServer() *AccordServer
func (*AccordServer) AddChannel ¶
func (s *AccordServer) AddChannel(ctx context.Context, req *pb.AddChannelRequest) (*pb.AddChannelResponse, error)
AddChannel creates a new channel with given parameters. The user who created the channel automatically becomes the channel's superadmin.
func (*AccordServer) ChannelStream ¶
func (s *AccordServer) ChannelStream(srv pb.Chat_ChannelStreamServer) error
ChannelStream is the implementation of bidirectional streaming of client with one channel on the server.
func (*AccordServer) GetChannel ¶
func (s *AccordServer) GetChannel(ctx context.Context, req *pb.GetChannelRequest) (*pb.GetChannelResponse, error)
func (*AccordServer) GetChannels ¶
func (s *AccordServer) GetChannels(ctx context.Context, req *pb.GetChannelsRequest) (*pb.GetChannelsResponse, error)
func (*AccordServer) LoadChannels ¶
func (s *AccordServer) LoadChannels() error
LoadChannels loads channels from the persistent storage
func (*AccordServer) LoadUsers ¶
func (s *AccordServer) LoadUsers() error
LoadUsers loads channels from the persistent storage
func (*AccordServer) RemoveChannel ¶
func (s *AccordServer) RemoveChannel(_ context.Context, req *pb.RemoveChannelRequest) (*pb.RemoveChannelResponse, error)
func (*AccordServer) Start ¶
func (s *AccordServer) Start()
type AuthClient ¶
type AuthClient struct {
pb.AuthServiceClient
}
AuthClient is a client to call authentication RPC
func NewAuthClient ¶
func NewAuthClient(cc *grpc.ClientConn) *AuthClient
NewAuthClient returns a new auth client
func (*AuthClient) CreateUser ¶
func (c *AuthClient) CreateUser(username string, password string) error
type AuthServer ¶
type AuthServer struct {
// contains filtered or unexported fields
}
AuthServer is the server for authentication
func (*AuthServer) CreateUser ¶
func (s *AuthServer) CreateUser(_ context.Context, req *pb.CreateUserRequest) (*pb.CreateUserResponse, error)
func (*AuthServer) GetUser ¶
func (s *AuthServer) GetUser(username string) *User
func (*AuthServer) JWTManager ¶
func (s *AuthServer) JWTManager() *JWTManager
func (*AuthServer) Login ¶
func (s *AuthServer) Login(_ context.Context, req *pb.LoginRequest) (*pb.LoginResponse, error)
func (*AuthServer) Logout ¶
func (s *AuthServer) Logout(_ context.Context, req *pb.LogoutRequest) (*pb.LogoutResponse, error)
type ChannelConfigMessage ¶
type ChannelConfigMessage struct {
Msg isChannelConfigMessageMsg
}
ChannelConfigMessage is used in ChannelStreamRequest- and Response to initiate and broadcast channel-related changes.
type ChannelStreamRequest ¶
type ChannelStreamRequest struct { ChannelID uint64 Msg isChannelStreamRequestMsg }
ChannelStreamRequest represents a stream request for a single channel.
func (*ChannelStreamRequest) GetChannelID ¶
func (m *ChannelStreamRequest) GetChannelID() uint64
func (*ChannelStreamRequest) GetConfMsg ¶
func (x *ChannelStreamRequest) GetConfMsg() *ChannelConfigMessage
func (*ChannelStreamRequest) GetMsg ¶
func (m *ChannelStreamRequest) GetMsg() isChannelStreamRequestMsg
func (*ChannelStreamRequest) GetUserMsg ¶
func (x *ChannelStreamRequest) GetUserMsg() *UserChannelStreamRequest
type ChannelStreamRequestType ¶
type ChannelStreamRequestType int
ChannelStreamRequestType is a type of channel stream request message.
const ( // FromUserChannelStreamRequestType is for sending new messages, and updating or // deletion of messages. FromUserChannelStreamRequestType ChannelStreamRequestType = iota // ChannelConfigChannelStreamRequestType carries channel configuration changes, // including name change, updating user roles, and specifying pinned message. ChannelConfigChannelStreamRequestType )
type ChannelStreamResponse ¶
type ChannelStreamResponse struct {
Msg isChannelStreamResponseMsg
}
type ChannelStreamResponseType ¶
type ChannelStreamResponseType int
ChannelStreamResponseType is a type of channel stream response message.
const ( // FromUserChannelStreamResponseType is for sending new messages, and updating or // deletion of messages. FromUserChannelStreamResponseType ChannelStreamResponseType = iota // ChannelConfigChannelStreamResponseType carries channel configuration changes, // including name change, updating user roles, and specifying pinned message. ChannelConfigChannelStreamResponseType )
type ClientAuthInterceptor ¶
type ClientAuthInterceptor struct {
// contains filtered or unexported fields
}
ClientAuthInterceptor is a client interceptor for authentication
func NewClientAuthInterceptor ¶
func NewClientAuthInterceptor( authClient *AuthClient, username string, password string, refreshDuration time.Duration, ) (*ClientAuthInterceptor, error)
NewClientAuthInterceptor returns a new auth interceptor
func (*ClientAuthInterceptor) Stream ¶
func (intr *ClientAuthInterceptor) Stream() grpc.StreamClientInterceptor
Stream returns a client interceptor to authenticate stream RPC
func (*ClientAuthInterceptor) Unary ¶
func (intr *ClientAuthInterceptor) Unary() grpc.UnaryClientInterceptor
Unary returns a client interceptor to authenticate unary RPC
type ClientChannel ¶
type ClientChannel struct { ChannelId uint64 Name string // Set if the **fixed** data for this channel has been fetched on the client side. // Data that is mutable (and is frequently updated) such as pinned message, channel name, // and messages, is not polled through "IsFetched". IsFetched bool IsPublic bool PinnedMsgId uint64 Users map[string]Role RolesWithPermission map[Permission][]Role Stream pb.Chat_ChannelStreamClient Messages []Message }
ClientChannel represents a single private or public messaging channel.
func NewClientChannel ¶
func NewClientChannel(uid uint64, name string, isPublic bool) *ClientChannel
NewClientChannel creates a new client channel with provided parameters.
type DeleteMessageUserChannelStreamRequest ¶
type DeleteMessageUserChannelStreamRequest struct {
MessageID uint64
}
type DeleteMessageUserChannelStreamResponse ¶
type DeleteMessageUserChannelStreamResponse struct{}
type JWTManager ¶
type JWTManager struct {
// contains filtered or unexported fields
}
JWTManager is a JSON web token manager
func NewJWTManager ¶
func NewJWTManager(secretKey string, tokenDuration time.Duration) *JWTManager
NewJWTManager returns a new JWT manager
func (*JWTManager) Generate ¶
func (manager *JWTManager) Generate(username string) (string, error)
Generate generates and signs a new token for a user
func (*JWTManager) Verify ¶
func (manager *JWTManager) Verify(accessToken string) (*UserClaims, error)
Verify verifies the access token string and return a user claim if the token is valid
type Message ¶
type Message struct { MessageID uint64 Timestamp time.Time // TODO: add "Sender" field, denoting the user, who sent the message. Content string }
Message is a single message in the chat
type NameChannelConfigMessage ¶
type NameChannelConfigMessage struct {
NewChannelName string
}
type NewMessageUserChannelStreamRequest ¶
type NewMessageUserChannelStreamRequest struct {
Content string
}
type Permission ¶
type Permission int
Permission represents actions allowed to the role within a channel.
const ( // UnknownPermission is needed as a part of mapping to unknown message // from "pb" package. UnknownPermission Permission = iota // ReadPermission is for subscribed users or any member of the channel ReadPermission // WritePermission includes writing, modifying, and deletion of messages WritePermission // DeletePermission allows deleting othes users' messages DeletePermission // ModifyPermission is for modifying channel configurations ModifyPermission // KickPermission is for kicking users out of the channel KickPermission // BanPermission is for banning users BanPermission // AssignRolePermission is for assignment of roles to all channel's users AssignRolePermission // RemoveChannelPermission is a permission to permanently remove the channel // and all of its data. RemoveChannelPermission )
type PinChannelConfigMessage ¶
type PinChannelConfigMessage struct {
MessageID uint64
}
type ServerAuthInterceptor ¶
type ServerAuthInterceptor struct {
// contains filtered or unexported fields
}
ServerAuthInterceptor is a server interceptor for authentication and authorization
func NewServerAuthInterceptor ¶
func NewServerAuthInterceptor(jwtManager *JWTManager) *ServerAuthInterceptor
NewServerAuthInterceptor returns a new auth interceptor
func (*ServerAuthInterceptor) Authorize ¶
func (interceptor *ServerAuthInterceptor) Authorize(ctx context.Context, method string) (*UserClaims, error)
func (*ServerAuthInterceptor) Stream ¶
func (interceptor *ServerAuthInterceptor) Stream() grpc.StreamServerInterceptor
Stream returns a server interceptor function to authenticate and authorize stream RPC
func (*ServerAuthInterceptor) Unary ¶
func (interceptor *ServerAuthInterceptor) Unary() grpc.UnaryServerInterceptor
Unary returns a server interceptor function to authenticate and authorize unary RPC
type ServerChannel ¶
type ServerChannel struct {
// contains filtered or unexported fields
}
ServerChannel represents a single private or public messaging channel.
func NewServerChannel ¶
func NewServerChannel(uid uint64, name string, isPublic bool) *ServerChannel
NewServerChannel creates a new server channel with provided parameters.
type StreamRequestCommunication ¶
type StreamRequestCommunication struct { Reqc chan<- *ChannelStreamRequest Closec <-chan struct{} }
StreamRequestCommunication is used as a communication interface for users
of this package who use "Stream" function.
type StreamResponseCommunication ¶
type StreamResponseCommunication struct { Resc <-chan *ChannelStreamResponse Closec chan<- struct{} }
StreamResponseCommunication is used as a communication interface for users
of this package who use "Stream" function.
type User ¶
type User struct {
// contains filtered or unexported fields
}
User contains user's information
func (*User) IsCorrectPassword ¶
IsCorrectPassword checks if the provided password is correct or not
type UserChannelStreamRequest ¶
type UserChannelStreamRequest struct {
UserMsg isUserChannelStreamRequestUserMsg
}
UserChannelStreamRequest is a stream message sent by one of the users to the channel.
type UserChannelStreamResponse ¶
type UserChannelStreamResponse struct { MessageID uint64 UserMsg isUserChannelStreamResponseUserMsg }
UserChannelStreamResponse is a stream message broadcasted to all users in the channel.
func (*UserChannelStreamResponse) GetDeleteUserMsg ¶
func (m *UserChannelStreamResponse) GetDeleteUserMsg() *DeleteMessageUserChannelStreamResponse
GetDeleteUserMsg gets the deleted message in user response message.
func (*UserChannelStreamResponse) GetMessageID ¶
func (m *UserChannelStreamResponse) GetMessageID() uint64
GetMessageID returns message ID or the user stream response. It returns 0 if the user stream response is nil.
func (*UserChannelStreamResponse) GetNewAndUpdateUserMsg ¶
func (m *UserChannelStreamResponse) GetNewAndUpdateUserMsg() *NewAndUpdateMessageUserChannelStreamResponse
GetNewAndUpdateUserMsg gets the new and update response messages from some user.
func (*UserChannelStreamResponse) GetUserMsg ¶
func (m *UserChannelStreamResponse) GetUserMsg() isUserChannelStreamResponseUserMsg
GetUserMsg returns the user message contained in the user channel stream response.
type UserClaims ¶
type UserClaims struct { jwt.StandardClaims Username string `json:"username"` }
UserClaims is a custom JWT claims that contains some user's information