Documentation ¶
Overview ¶
Package api implements a client for interacting with the server. It provides both grpc and https variants.
Index ¶
- Variables
- type GRPCSender
- func (g *GRPCSender) AddBin(binary *models.Binary) error
- func (g *GRPCSender) AddCard(card *models.Card) error
- func (g *GRPCSender) AddLogin(login *models.Login) error
- func (g *GRPCSender) AddText(text *models.Text) error
- func (g *GRPCSender) Bin(binID string) (*models.Binary, error)
- func (g *GRPCSender) Card(cardID string) (*models.Card, error)
- func (g *GRPCSender) DelBin(binID string) error
- func (g *GRPCSender) DelCard(cardID string) error
- func (g *GRPCSender) DelLogin(loginID string) error
- func (g *GRPCSender) DelText(textID string) error
- func (g *GRPCSender) Login(loginID string) (*models.Login, error)
- func (g *GRPCSender) Register(login string, pwd string) error
- func (g *GRPCSender) SignIn(login string, pwd string) error
- func (g *GRPCSender) Text(textID string) (*models.Text, error)
- type HTTPSender
- func (s *HTTPSender) AddBin(binary *models.Binary) error
- func (s *HTTPSender) AddCard(card *models.Card) error
- func (s *HTTPSender) AddLogin(login *models.Login) error
- func (s *HTTPSender) AddText(text *models.Text) error
- func (s *HTTPSender) Bin(binID string) (*models.Binary, error)
- func (s *HTTPSender) Card(cardID string) (*models.Card, error)
- func (s *HTTPSender) DelBin(binID string) error
- func (s *HTTPSender) DelCard(cardID string) error
- func (s *HTTPSender) DelLogin(loginID string) error
- func (s *HTTPSender) DelText(textID string) error
- func (s *HTTPSender) Login(loginID string) (*models.Login, error)
- func (s *HTTPSender) Register(login string, pwd string) error
- func (s *HTTPSender) SignIn(login string, pwd string) error
- func (s *HTTPSender) Text(textID string) (*models.Text, error)
- type Sender
Constants ¶
This section is empty.
Variables ¶
var ( FmtErrInternalServer = "server unavailable, please try later: %w" FmtErrServerTimout = "server unavailable, please try later: %w" FmtErrDeserialization = "deserialization error: %w" FmtErrRequestPrepare = "failed to prepare http request: %w" FmtErrUserAlreadyExists = "a user with this login is already registered: %w" FmtErrUserNotFound = "a user with this login was not found: %w" FmtErrAlreadyExists = "ID with this identifier is already registered: %w" FmtErrNotFound = "record with this identifier was not found: %w" FmtErrSerialization = "serialization error: %w" ErrSerialization = errors.New("serialization error") ErrAuthRequire = errors.New("authorization required") ErrUserAlreadyExists = errors.New("a user with this login is already registered") ErrInternalServer = errors.New("server unavailable, please try later") ErrUserNotFound = errors.New("a user with this login was not found") ErrAlreadyExists = errors.New("ID with this identifier is already registered") ErrNotFound = errors.New("record with this identifier was not found") )
List of errors that the client can generate when interacting with the server While some errors in the http client come as StatusCode with no error message. Then we generate an error, and if a grpc error occurs, we propagate it using the error format
Functions ¶
This section is empty.
Types ¶
type GRPCSender ¶
type GRPCSender struct {
// contains filtered or unexported fields
}
GRPCSender structure of the grpc client. Implements the Sender interface. See the respective methods for all comments.
func NewGRPCSender ¶
func NewGRPCSender(conf *config.Config) (*GRPCSender, error)
NewGRPCSender constructor
func (*GRPCSender) DelBin ¶
func (g *GRPCSender) DelBin(binID string) error
func (*GRPCSender) DelCard ¶
func (g *GRPCSender) DelCard(cardID string) error
func (*GRPCSender) DelLogin ¶
func (g *GRPCSender) DelLogin(loginID string) error
func (*GRPCSender) DelText ¶
func (g *GRPCSender) DelText(textID string) error
type HTTPSender ¶
HTTPSender structure of the http client. Implements the Sender interface. See the respective methods for all comments.
func NewHTTPSender ¶
func NewHTTPSender(conf *config.Config) (*HTTPSender, error)
NewHTTPSender constructor for the http client
func (*HTTPSender) DelBin ¶
func (s *HTTPSender) DelBin(binID string) error
func (*HTTPSender) DelCard ¶
func (s *HTTPSender) DelCard(cardID string) error
func (*HTTPSender) DelLogin ¶
func (s *HTTPSender) DelLogin(loginID string) error
func (*HTTPSender) DelText ¶
func (s *HTTPSender) DelText(textID string) error
type Sender ¶
type Sender interface { // Register request to the server for client registration Register(login string, pwd string) error // SignIn request to the server for client authorization SignIn(login string, pwd string) error // AddCard request to add a new card AddCard(card *models.Card) error // Card request to read an existing card by id Card(cardID string) (*models.Card, error) // DelCard request to delete an existing card by id DelCard(cardID string) error // AddLogin request to add a new login AddLogin(login *models.Login) error // Login request to read an existing login by id Login(loginID string) (*models.Login, error) // DelLogin request to delete an existing login by id DelLogin(loginID string) error // AddText request to add new text content AddText(text *models.Text) error // Text request to read existing text content by id Text(textID string) (*models.Text, error) // DelText request to delete existing text content by id DelText(textID string) error // AddBin request to add new binary data AddBin(binary *models.Binary) error // Bin request to read existing binary data by id Bin(binID string) (*models.Binary, error) // DelBin request to delete existing binary data by id DelBin(binID string) error }
Sender any client for working with the server should implement this interface