Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterUserServiceServer(s *grpc.Server, srv UserServiceServer)
- func SessionsGRPCClientFactory(logger logger.Logger, cfg *config.Config, tracer opentracing.Tracer) ...
- type Application
- type GetByIDRequest
- type GetByIDResponse
- type GetUsersByIDsRequest
- func (*GetUsersByIDsRequest) Descriptor() ([]byte, []int)deprecated
- func (x *GetUsersByIDsRequest) GetUsersIDs() []string
- func (*GetUsersByIDsRequest) ProtoMessage()
- func (x *GetUsersByIDsRequest) ProtoReflect() protoreflect.Message
- func (x *GetUsersByIDsRequest) Reset()
- func (x *GetUsersByIDsRequest) String() string
- type GetUsersByIDsResponse
- func (*GetUsersByIDsResponse) Descriptor() ([]byte, []int)deprecated
- func (x *GetUsersByIDsResponse) GetUsers() []*User
- func (*GetUsersByIDsResponse) ProtoMessage()
- func (x *GetUsersByIDsResponse) ProtoReflect() protoreflect.Message
- func (x *GetUsersByIDsResponse) Reset()
- func (x *GetUsersByIDsResponse) String() string
- type HTTPTransport
- func (h *HTTPTransport) Delete() echo.HandlerFunc
- func (h *HTTPTransport) GetCSRFToken() echo.HandlerFunc
- func (h *HTTPTransport) GetMe() echo.HandlerFunc
- func (h *HTTPTransport) GetUserByID() echo.HandlerFunc
- func (h *HTTPTransport) Login() echo.HandlerFunc
- func (h *HTTPTransport) Logout() echo.HandlerFunc
- func (h *HTTPTransport) MapUserRoutes()
- func (h *HTTPTransport) Register() echo.HandlerFunc
- func (h *HTTPTransport) Update() echo.HandlerFunc
- func (h *HTTPTransport) UpdateAvatar() echo.HandlerFunc
- type Login
- type Publisher
- type PublisherImpl
- type RabbitConsumerImpl
- type RedisRepository
- type RedisRepositoryImpl
- type Repository
- type RepositoryImpl
- func (u *RepositoryImpl) Create(ctx context.Context, user *UserDO) (*UserResponse, error)
- func (u *RepositoryImpl) GetByEmail(ctx context.Context, email string) (*UserDO, error)
- func (u *RepositoryImpl) GetByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error)
- func (u *RepositoryImpl) GetUsersByIDs(ctx context.Context, userIDs []string) ([]*UserResponse, error)
- func (u *RepositoryImpl) Update(ctx context.Context, user *UserUpdate) (*UserResponse, error)
- func (u *RepositoryImpl) UpdateAvatar(ctx context.Context, msg images.UploadedImageMsg) (*UserResponse, error)
- type RequestCtxSession
- type RequestCtxUser
- type Role
- type ServerImpl
- type Service
- type ServiceImpl
- func (s *ServiceImpl) CreateSession(ctx context.Context, userID uuid.UUID) (string, error)
- func (s *ServiceImpl) DeleteSession(ctx context.Context, sessionID string) error
- func (s *ServiceImpl) GetByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error)
- func (s *ServiceImpl) GetCSRFToken(ctx context.Context, sessionID string) (string, error)
- func (s *ServiceImpl) GetSessionByID(ctx context.Context, sessionID string) (*sessions.SessionDO, error)
- func (s *ServiceImpl) GetUsersByIDs(ctx context.Context, userIDs []string) ([]*UserResponse, error)
- func (s *ServiceImpl) Login(ctx context.Context, login Login) (*UserDO, error)
- func (s *ServiceImpl) Register(ctx context.Context, user *UserDO) (*UserResponse, error)
- func (s *ServiceImpl) Update(ctx context.Context, user *UserUpdate) (*UserResponse, error)
- func (s *ServiceImpl) UpdateAvatar(ctx context.Context, data *images.UpdateAvatarMsg) error
- func (s *ServiceImpl) UpdateUploadedAvatar(ctx context.Context, delivery amqp.Delivery) error
- type SessionManager
- type UnimplementedUserServiceServer
- type User
- func (*User) Descriptor() ([]byte, []int)deprecated
- func (x *User) GetAvatar() string
- func (x *User) GetCreatedAt() *timestamp.Timestamp
- func (x *User) GetEmail() string
- func (x *User) GetFirstName() string
- func (x *User) GetLastName() string
- func (x *User) GetRole() string
- func (x *User) GetUpdatedAt() *timestamp.Timestamp
- func (x *User) GetUserID() string
- func (*User) ProtoMessage()
- func (x *User) ProtoReflect() protoreflect.Message
- func (x *User) Reset()
- func (x *User) String() string
- type UserDO
- type UserResponse
- type UserServiceClient
- type UserServiceServer
- type UserUpdate
Constants ¶
const ( UserExchange = "users" AvatarsQueueName = "avatars_queue" AvatarsConsumerTag = "user_avatar_consumer" AvatarsWorkers = 5 AvatarsBindingKey = "update_avatar_key" )
Variables ¶
var File_app_users_user_proto protoreflect.FileDescriptor
Functions ¶
func RegisterUserServiceServer ¶
func RegisterUserServiceServer(s *grpc.Server, srv UserServiceServer)
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func NewApplication ¶
func (*Application) MapRoutes ¶
func (a *Application) MapRoutes()
func (*Application) Run ¶
func (a *Application) Run() error
type GetByIDRequest ¶
type GetByIDRequest struct { UserID string `protobuf:"bytes,1,opt,name=UserID,proto3" json:"UserID,omitempty"` // contains filtered or unexported fields }
func (*GetByIDRequest) Descriptor
deprecated
func (*GetByIDRequest) Descriptor() ([]byte, []int)
Deprecated: Use GetByIDRequest.ProtoReflect.Descriptor instead.
func (*GetByIDRequest) GetUserID ¶
func (x *GetByIDRequest) GetUserID() string
func (*GetByIDRequest) ProtoMessage ¶
func (*GetByIDRequest) ProtoMessage()
func (*GetByIDRequest) ProtoReflect ¶
func (x *GetByIDRequest) ProtoReflect() protoreflect.Message
func (*GetByIDRequest) Reset ¶
func (x *GetByIDRequest) Reset()
func (*GetByIDRequest) String ¶
func (x *GetByIDRequest) String() string
type GetByIDResponse ¶
type GetByIDResponse struct { User *User `protobuf:"bytes,1,opt,name=User,proto3" json:"User,omitempty"` // contains filtered or unexported fields }
func (*GetByIDResponse) Descriptor
deprecated
func (*GetByIDResponse) Descriptor() ([]byte, []int)
Deprecated: Use GetByIDResponse.ProtoReflect.Descriptor instead.
func (*GetByIDResponse) GetUser ¶
func (x *GetByIDResponse) GetUser() *User
func (*GetByIDResponse) ProtoMessage ¶
func (*GetByIDResponse) ProtoMessage()
func (*GetByIDResponse) ProtoReflect ¶
func (x *GetByIDResponse) ProtoReflect() protoreflect.Message
func (*GetByIDResponse) Reset ¶
func (x *GetByIDResponse) Reset()
func (*GetByIDResponse) String ¶
func (x *GetByIDResponse) String() string
type GetUsersByIDsRequest ¶
type GetUsersByIDsRequest struct { UsersIDs []string `protobuf:"bytes,1,rep,name=UsersIDs,proto3" json:"UsersIDs,omitempty"` // contains filtered or unexported fields }
func (*GetUsersByIDsRequest) Descriptor
deprecated
func (*GetUsersByIDsRequest) Descriptor() ([]byte, []int)
Deprecated: Use GetUsersByIDsRequest.ProtoReflect.Descriptor instead.
func (*GetUsersByIDsRequest) GetUsersIDs ¶
func (x *GetUsersByIDsRequest) GetUsersIDs() []string
func (*GetUsersByIDsRequest) ProtoMessage ¶
func (*GetUsersByIDsRequest) ProtoMessage()
func (*GetUsersByIDsRequest) ProtoReflect ¶
func (x *GetUsersByIDsRequest) ProtoReflect() protoreflect.Message
func (*GetUsersByIDsRequest) Reset ¶
func (x *GetUsersByIDsRequest) Reset()
func (*GetUsersByIDsRequest) String ¶
func (x *GetUsersByIDsRequest) String() string
type GetUsersByIDsResponse ¶
type GetUsersByIDsResponse struct { Users []*User `protobuf:"bytes,1,rep,name=Users,proto3" json:"Users,omitempty"` // contains filtered or unexported fields }
func (*GetUsersByIDsResponse) Descriptor
deprecated
func (*GetUsersByIDsResponse) Descriptor() ([]byte, []int)
Deprecated: Use GetUsersByIDsResponse.ProtoReflect.Descriptor instead.
func (*GetUsersByIDsResponse) GetUsers ¶
func (x *GetUsersByIDsResponse) GetUsers() []*User
func (*GetUsersByIDsResponse) ProtoMessage ¶
func (*GetUsersByIDsResponse) ProtoMessage()
func (*GetUsersByIDsResponse) ProtoReflect ¶
func (x *GetUsersByIDsResponse) ProtoReflect() protoreflect.Message
func (*GetUsersByIDsResponse) Reset ¶
func (x *GetUsersByIDsResponse) Reset()
func (*GetUsersByIDsResponse) String ¶
func (x *GetUsersByIDsResponse) String() string
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
func NewHTTPServer ¶
func NewHTTPServer( group *echo.Group, service Service, logger logger.Logger, validate *validator.Validate, cfg *config.Config, mw *SessionManager, ) HTTPTransport
func (*HTTPTransport) Delete ¶
func (h *HTTPTransport) Delete() echo.HandlerFunc
func (*HTTPTransport) GetCSRFToken ¶
func (h *HTTPTransport) GetCSRFToken() echo.HandlerFunc
GetCSRFToken godoc @Summary Get csrf token @Tags UserDO @Description Get csrf token, required session @Accept json @Produce json @Success 204 "" @Router /api/v1/users/csrf [get]
func (*HTTPTransport) GetMe ¶
func (h *HTTPTransport) GetMe() echo.HandlerFunc
GetMe godoc @Summary Get current user data @Tags UserDO @Description Get current user data, required session cookie @Accept json @Produce json @Success 200 {object} UserResponse @Router /api/v1/users/me [get]
func (*HTTPTransport) GetUserByID ¶
func (h *HTTPTransport) GetUserByID() echo.HandlerFunc
GetUserByID godoc @Summary Get user by id @Tags UserDO @Description Get user data by id @Accept json @Produce json @Param id path int false "user uuid" @Success 200 {object} UserResponse @Router /api/v1/users/{id} [get]
func (*HTTPTransport) Login ¶
func (h *HTTPTransport) Login() echo.HandlerFunc
Login godoc @Summary Login user @Tags UserDO @Description login user, returns user data and session @Accept json @Produce json @Param data body Login true "email and password" @Success 200 {object} UserResponse @Router /api/v1/users/login [post]
func (*HTTPTransport) Logout ¶
func (h *HTTPTransport) Logout() echo.HandlerFunc
Logout godoc @Summary Logout user @Tags UserDO @Description Logout user, return no content @Accept json @Produce json @Success 204 "" @Router /api/v1/users/logout [post]
func (*HTTPTransport) MapUserRoutes ¶
func (h *HTTPTransport) MapUserRoutes()
func (*HTTPTransport) Register ¶
func (h *HTTPTransport) Register() echo.HandlerFunc
Register godoc @Summary Register new user @Tags UserDO @Description register new user account, returns user data and session @Accept json @Produce json @Param data body UserDO true "user data" @Success 201 {object} UserResponse @Router /api/v1/users/register [post]
func (*HTTPTransport) Update ¶
func (h *HTTPTransport) Update() echo.HandlerFunc
Update godoc @Summary Update user @Tags UserDO @Description update user profile @Accept json @Produce json @Success 200 {object} UserResponse @Router /api/v1/users/{id} [put]
func (*HTTPTransport) UpdateAvatar ¶
func (h *HTTPTransport) UpdateAvatar() echo.HandlerFunc
UpdateAvatar godoc @Summary Update user avatar @Tags UserDO @Description Upload user avatar image @Accept mpfd @Produce json @Param id path int false "user uuid" @Success 200 {object} UserResponse @Router /api/v1/users/{id}/avatar [put]
type PublisherImpl ¶
type PublisherImpl struct {
// contains filtered or unexported fields
}
func NewUserPublisher ¶
func (*PublisherImpl) CreateExchangeAndQueue ¶
func (p *PublisherImpl) CreateExchangeAndQueue(exchange, queueName, bindingKey string) (*amqp.Channel, error)
type RabbitConsumerImpl ¶
type RabbitConsumerImpl struct {
// contains filtered or unexported fields
}
func NewConsumer ¶
func (*RabbitConsumerImpl) CreateExchangeAndQueue ¶
func (c *RabbitConsumerImpl) CreateExchangeAndQueue(exchangeName, queueName, bindingKey string) (*amqp.Channel, error)
Consume messages
func (*RabbitConsumerImpl) Dial ¶
func (c *RabbitConsumerImpl) Dial() error
func (*RabbitConsumerImpl) RunConsumers ¶
func (c *RabbitConsumerImpl) RunConsumers(ctx context.Context, cancel context.CancelFunc)
type RedisRepository ¶
type RedisRepositoryImpl ¶
type RedisRepositoryImpl struct {
// contains filtered or unexported fields
}
func NewRedisRepository ¶
func NewRedisRepository(redisConn *redis.Client, prefix string, expiration time.Duration) RedisRepositoryImpl
func (*RedisRepositoryImpl) DeleteUser ¶
func (*RedisRepositoryImpl) GetUserByID ¶
func (u *RedisRepositoryImpl) GetUserByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error)
func (*RedisRepositoryImpl) SaveUser ¶
func (u *RedisRepositoryImpl) SaveUser(ctx context.Context, user *UserResponse) error
type Repository ¶
type Repository interface { Create(ctx context.Context, user *UserDO) (*UserResponse, error) GetByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error) GetByEmail(ctx context.Context, email string) (*UserDO, error) Update(ctx context.Context, user *UserUpdate) (*UserResponse, error) UpdateAvatar(ctx context.Context, msg images.UploadedImageMsg) (*UserResponse, error) GetUsersByIDs(ctx context.Context, userIDs []string) ([]*UserResponse, error) }
type RepositoryImpl ¶
type RepositoryImpl struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(db *pgxpool.Pool) RepositoryImpl
func (*RepositoryImpl) Create ¶
func (u *RepositoryImpl) Create(ctx context.Context, user *UserDO) (*UserResponse, error)
Create new user
func (*RepositoryImpl) GetByEmail ¶
func (*RepositoryImpl) GetByID ¶
func (u *RepositoryImpl) GetByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error)
Get user by id
func (*RepositoryImpl) GetUsersByIDs ¶
func (u *RepositoryImpl) GetUsersByIDs(ctx context.Context, userIDs []string) ([]*UserResponse, error)
func (*RepositoryImpl) Update ¶
func (u *RepositoryImpl) Update(ctx context.Context, user *UserUpdate) (*UserResponse, error)
func (*RepositoryImpl) UpdateAvatar ¶
func (u *RepositoryImpl) UpdateAvatar(ctx context.Context, msg images.UploadedImageMsg) (*UserResponse, error)
type RequestCtxSession ¶
type RequestCtxSession struct{}
type RequestCtxUser ¶
type RequestCtxUser struct{}
type ServerImpl ¶
type ServerImpl struct {
// contains filtered or unexported fields
}
func (*ServerImpl) GetUserByID ¶
func (e *ServerImpl) GetUserByID(ctx context.Context, r *GetByIDRequest) (*GetByIDResponse, error)
func (*ServerImpl) GetUsersByIDs ¶
func (e *ServerImpl) GetUsersByIDs(ctx context.Context, req *GetUsersByIDsRequest) (*GetUsersByIDsResponse, error)
type Service ¶
type Service interface { Register(ctx context.Context, user *UserDO) (*UserResponse, error) Login(ctx context.Context, login Login) (*UserDO, error) GetByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error) CreateSession(ctx context.Context, userID uuid.UUID) (string, error) GetSessionByID(ctx context.Context, sessionID string) (*sessions.SessionDO, error) GetCSRFToken(ctx context.Context, sessionID string) (string, error) DeleteSession(ctx context.Context, sessionID string) error Update(ctx context.Context, user *UserUpdate) (*UserResponse, error) UpdateUploadedAvatar(ctx context.Context, delivery amqp.Delivery) error UpdateAvatar(ctx context.Context, data *images.UpdateAvatarMsg) error GetUsersByIDs(ctx context.Context, userIDs []string) ([]*UserResponse, error) }
type ServiceImpl ¶
type ServiceImpl struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService( repository Repository, redisRepository RedisRepository, log logger.Logger, amqpPublisher Publisher, grpcClientFactory func(ctx context.Context) (*grpc.ClientConn, sessions.AuthorizationServiceClient, error), ) ServiceImpl
func (*ServiceImpl) CreateSession ¶
func (*ServiceImpl) DeleteSession ¶
func (s *ServiceImpl) DeleteSession(ctx context.Context, sessionID string) error
func (*ServiceImpl) GetByID ¶
func (s *ServiceImpl) GetByID(ctx context.Context, userID uuid.UUID) (*UserResponse, error)
func (*ServiceImpl) GetCSRFToken ¶
func (*ServiceImpl) GetSessionByID ¶
func (*ServiceImpl) GetUsersByIDs ¶
func (s *ServiceImpl) GetUsersByIDs(ctx context.Context, userIDs []string) ([]*UserResponse, error)
func (*ServiceImpl) Register ¶
func (s *ServiceImpl) Register(ctx context.Context, user *UserDO) (*UserResponse, error)
func (*ServiceImpl) Update ¶
func (s *ServiceImpl) Update(ctx context.Context, user *UserUpdate) (*UserResponse, error)
func (*ServiceImpl) UpdateAvatar ¶
func (s *ServiceImpl) UpdateAvatar(ctx context.Context, data *images.UpdateAvatarMsg) error
func (*ServiceImpl) UpdateUploadedAvatar ¶
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func (*SessionManager) SessionMiddleware ¶
func (m *SessionManager) SessionMiddleware(next echo.HandlerFunc) echo.HandlerFunc
type UnimplementedUserServiceServer ¶
type UnimplementedUserServiceServer struct { }
UnimplementedUserServiceServer can be embedded to have forward compatible implementations.
func (*UnimplementedUserServiceServer) GetUserByID ¶
func (*UnimplementedUserServiceServer) GetUserByID(context.Context, *GetByIDRequest) (*GetByIDResponse, error)
func (*UnimplementedUserServiceServer) GetUsersByIDs ¶
func (*UnimplementedUserServiceServer) GetUsersByIDs(context.Context, *GetUsersByIDsRequest) (*GetUsersByIDsResponse, error)
type User ¶
type User struct { CreatedAt *timestamp.Timestamp `protobuf:"bytes,7,opt,name=CreatedAt,proto3" json:"CreatedAt,omitempty"` UpdatedAt *timestamp.Timestamp `protobuf:"bytes,8,opt,name=UpdatedAt,proto3" json:"UpdatedAt,omitempty"` UserID string `protobuf:"bytes,1,opt,name=UserID,proto3" json:"UserID,omitempty"` FirstName string `protobuf:"bytes,2,opt,name=FirstName,proto3" json:"FirstName,omitempty"` LastName string `protobuf:"bytes,3,opt,name=LastName,proto3" json:"LastName,omitempty"` Email string `protobuf:"bytes,4,opt,name=Email,proto3" json:"Email,omitempty"` Avatar string `protobuf:"bytes,5,opt,name=Avatar,proto3" json:"Avatar,omitempty"` Role string `protobuf:"bytes,6,opt,name=Role,proto3" json:"Role,omitempty"` // contains filtered or unexported fields }
func (*User) Descriptor
deprecated
func (*User) GetCreatedAt ¶
func (*User) GetFirstName ¶
func (*User) GetLastName ¶
func (*User) GetUpdatedAt ¶
func (*User) ProtoMessage ¶
func (*User) ProtoMessage()
func (*User) ProtoReflect ¶
func (x *User) ProtoReflect() protoreflect.Message
type UserDO ¶
type UserDO struct { Role *Role `json:"role"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"updated_at"` FirstName string `json:"first_name" validate:"required,min=3,max=25"` LastName string `json:"last_name" validate:"required,min=3,max=25"` Email string `json:"email" validate:"required,email"` Password string `json:"password" validate:"required,min=6,max=250"` Avatar postgres.NullString `json:"avatar" validate:"max=250" swaggertype:"string"` UserID uuid.UUID `json:"user_id"` }
func (*UserDO) ComparePasswords ¶
Compare user password and payload
type UserResponse ¶
type UserResponse struct { Role *Role `json:"role"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"updated_at"` FirstName string `json:"first_name" validate:"required,min=3,max=25"` LastName string `json:"last_name" validate:"required,min=3,max=25"` Email string `json:"email" validate:"required,email"` Avatar postgres.NullString `json:"avatar" validate:"max=250" swaggertype:"string"` UserID uuid.UUID `json:"user_id"` }
func (*UserResponse) ToProto ¶
func (r *UserResponse) ToProto() *User
type UserServiceClient ¶
type UserServiceClient interface { GetUserByID(ctx context.Context, in *GetByIDRequest, opts ...grpc.CallOption) (*GetByIDResponse, error) GetUsersByIDs(ctx context.Context, in *GetUsersByIDsRequest, opts ...grpc.CallOption) (*GetUsersByIDsResponse, error) }
UserServiceClient is the client API for UserService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewUserServiceClient ¶
func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient
type UserServiceServer ¶
type UserServiceServer interface { GetUserByID(context.Context, *GetByIDRequest) (*GetByIDResponse, error) GetUsersByIDs(context.Context, *GetUsersByIDsRequest) (*GetUsersByIDsResponse, error) }
UserServiceServer is the server API for UserService service.
type UserUpdate ¶
type UserUpdate struct { Role *Role `json:"role"` FirstName string `json:"first_name" validate:"omitempty,min=3,max=25" swaggertype:"string"` LastName string `json:"last_name" validate:"omitempty,min=3,max=25" swaggertype:"string"` Email string `json:"email" validate:"omitempty,email" swaggertype:"string"` Avatar string `json:"avatar" validate:"max=250" swaggertype:"string"` UserID uuid.UUID `json:"user_id"` }