Documentation ¶
Index ¶
- Variables
- type AuthInterceptor
- type AuthServer
- type DiskImageStore
- type ImageInfo
- type ImageStore
- type InMemoryLaptopStore
- type InMemoryRatingStore
- type InMemoryUserStore
- type JWTManager
- type LaptopServer
- func (server *LaptopServer) CreateLaptop(ctx context.Context, req *pb.CreateLaptopRequest) (*pb.CreateLaptopResponse, error)
- func (server *LaptopServer) RateLaptop(stream pb.LaptopService_RateLaptopServer) error
- func (server *LaptopServer) SearchLaptop(req *pb.SearchLaptopRequest, stream pb.LaptopService_SearchLaptopServer) error
- func (server *LaptopServer) UploadImage(stream pb.LaptopService_UploadImageServer) error
- type LaptopStore
- type Rating
- type RatingStore
- type User
- type UserClaims
- type UserStore
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("record already exists")
ErrAlreadyExists is returned when a record with the same ID already exists in the store
Functions ¶
This section is empty.
Types ¶
type AuthInterceptor ¶
type AuthInterceptor struct {
// contains filtered or unexported fields
}
func NewAuthInterceptor ¶
func NewAuthInterceptor(jwtManager *JWTManager, accessibleRoles map[string][]string) *AuthInterceptor
NewAuthInterceptor returns a new auth interceptor
func (*AuthInterceptor) Stream ¶
func (interceptor *AuthInterceptor) Stream() grpc.StreamServerInterceptor
Stream returns a server interceptor function to authenticate and authorize stream RPC
func (*AuthInterceptor) Unary ¶
func (interceptor *AuthInterceptor) Unary() grpc.UnaryServerInterceptor
Unary returns a server interceptor function to authenticate and authorize unary RPC
type AuthServer ¶
type AuthServer struct { // pb.AuthServiceServer // for backward compatibility pb.UnimplementedAuthServiceServer // contains filtered or unexported fields }
AuthServer is the server for authentication
func NewAuthServer ¶
func NewAuthServer(userStore UserStore, jwtManager *JWTManager) *AuthServer
NewAuthServer returns a new auth server
func (*AuthServer) Login ¶
func (server *AuthServer) Login(ctx context.Context, req *pb.LoginRequest) (*pb.LoginResponse, error)
Login is a unary RPC to login user
type DiskImageStore ¶
type DiskImageStore struct {
// contains filtered or unexported fields
}
DiskImageStore images on disk and its info on memory
func NewDiskImageStore ¶
func NewDiskImageStore(imageFolder string) *DiskImageStore
NewDiskImageStore returns a new DiskImageStore
type ImageStore ¶
type ImageStore interface { // Save saves a new laptop image to the store Save(laptopID string, imageType string, imageData bytes.Buffer) (string, error) }
ImageStore is an interface to store images
type InMemoryLaptopStore ¶
type InMemoryLaptopStore struct {
// contains filtered or unexported fields
}
InMemoryLaptopStore stores laptop in memory
func NewInMemoryLaptopStore ¶
func NewInMemoryLaptopStore() *InMemoryLaptopStore
NewInMemoryLaptopStore returns a new InMemoryLaptopStore
func (*InMemoryLaptopStore) Find ¶
func (store *InMemoryLaptopStore) Find(id string) (*pb.Laptop, error)
type InMemoryRatingStore ¶
type InMemoryRatingStore struct {
// contains filtered or unexported fields
}
InMemoryRatingStore stores laptop ratings in memory
func NewInMemoryRatingStore ¶
func NewInMemoryRatingStore() *InMemoryRatingStore
NewInMemoryRatingStore returns a new InMemoryRatingStore
type InMemoryUserStore ¶
type InMemoryUserStore struct {
// contains filtered or unexported fields
}
InMemoryUserStore stores users in memory
func NewInMemoryUserStore ¶
func NewInMemoryUserStore() *InMemoryUserStore
NewInMemoryUserStore returns a new in-memory user store
func (*InMemoryUserStore) Find ¶
func (store *InMemoryUserStore) Find(username string) (*User, error)
Find finds a user by username
func (*InMemoryUserStore) Save ¶
func (store *InMemoryUserStore) Save(user *User) error
Save saves a user to the store
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(user *User) (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 LaptopServer ¶
type LaptopServer struct { // pb.LaptopServiceServer/ // for backward compatibility pb.UnimplementedLaptopServiceServer // contains filtered or unexported fields }
LaptopServer is the server that provides laptop services
func NewLaptopServer ¶
func NewLaptopServer(laptopStore LaptopStore, imageStore ImageStore, ratingStore RatingStore) *LaptopServer
NewLaptopServer returns a new LaptopServer
func (*LaptopServer) CreateLaptop ¶
func (server *LaptopServer) CreateLaptop( ctx context.Context, req *pb.CreateLaptopRequest, ) (*pb.CreateLaptopResponse, error)
CreateLaptop is a unary RPC to create a new laptop
func (*LaptopServer) RateLaptop ¶
func (server *LaptopServer) RateLaptop(stream pb.LaptopService_RateLaptopServer) error
RateLaptop is a bidirectional-streaming RPC that allows client to rate a stream of laptops with a score, and returns a stream of average score for each of them
func (*LaptopServer) SearchLaptop ¶
func (server *LaptopServer) SearchLaptop( req *pb.SearchLaptopRequest, stream pb.LaptopService_SearchLaptopServer, ) error
SearchLaptop is a server-streaming RPC to search for laptops
func (*LaptopServer) UploadImage ¶
func (server *LaptopServer) UploadImage(stream pb.LaptopService_UploadImageServer) error
UploadImage is a client-streaming RPC to upload a laptop image
type LaptopStore ¶
type LaptopStore interface { // Save saves the laptop to the store Save(laptop *pb.Laptop) error // Find finds a laptop by ID Find(id string) (*pb.Laptop, error) // Search searches for laptops with filter, returns one by one via the found function Search(ctx context.Context, filter *pb.Filter, found func(laptop *pb.Laptop) error) error }
LaptopStore is an interface to store laptop
type RatingStore ¶
type RatingStore interface { // Add adds a new laptop score to the store and returns its rating Add(laptopID string, score float64) (*Rating, error) }
RatingStore is an interface to store laptop ratings
type User ¶
User contains user's information
func (*User) IsCorrectPassword ¶
IsCorrectPassword if the provided password is correct or not
type UserClaims ¶
type UserClaims struct { jwt.StandardClaims Username string `json:"username"` Role string `json:"role"` }
UserClaims is a custom JWT claims that contains some user's information