api

package
v0.0.0-...-2db41fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package api implements a client for interacting with the server. It provides both grpc and https variants.

Index

Constants

This section is empty.

Variables

View Source
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) AddBin

func (g *GRPCSender) AddBin(binary *models.Binary) error

func (*GRPCSender) AddCard

func (g *GRPCSender) AddCard(card *models.Card) error

func (*GRPCSender) AddLogin

func (g *GRPCSender) AddLogin(login *models.Login) error

func (*GRPCSender) AddText

func (g *GRPCSender) AddText(text *models.Text) error

func (*GRPCSender) Bin

func (g *GRPCSender) Bin(binID string) (*models.Binary, error)

func (*GRPCSender) Card

func (g *GRPCSender) Card(cardID string) (*models.Card, error)

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

func (*GRPCSender) Login

func (g *GRPCSender) Login(loginID string) (*models.Login, error)

func (*GRPCSender) Register

func (g *GRPCSender) Register(login string, pwd string) error

func (*GRPCSender) SignIn

func (g *GRPCSender) SignIn(login string, pwd string) error

func (*GRPCSender) Text

func (g *GRPCSender) Text(textID string) (*models.Text, error)

type HTTPSender

type HTTPSender struct {
	Client    *http.Client
	Conf      *config.Config
	AuthToken *string
}

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) AddBin

func (s *HTTPSender) AddBin(binary *models.Binary) error

func (*HTTPSender) AddCard

func (s *HTTPSender) AddCard(card *models.Card) error

func (*HTTPSender) AddLogin

func (s *HTTPSender) AddLogin(login *models.Login) error

func (*HTTPSender) AddText

func (s *HTTPSender) AddText(text *models.Text) error

func (*HTTPSender) Bin

func (s *HTTPSender) Bin(binID string) (*models.Binary, error)

func (*HTTPSender) Card

func (s *HTTPSender) Card(cardID string) (*models.Card, error)

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

func (*HTTPSender) Login

func (s *HTTPSender) Login(loginID string) (*models.Login, error)

func (*HTTPSender) Register

func (s *HTTPSender) Register(login string, pwd string) error

func (*HTTPSender) SignIn

func (s *HTTPSender) SignIn(login string, pwd string) error

func (*HTTPSender) Text

func (s *HTTPSender) Text(textID string) (*models.Text, 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

func CreateSender

func CreateSender(conf *config.Config) (Sender, error)

CreateSender function creates either an https or grpc client based on the settings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL