images

package
v0.0.0-...-f5cdc36 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExchangeName = "images"

	ResizeQueueName   = "resize_queue"
	ResizeConsumerTag = "resize_consumer"
	ResizeWorkers     = 10
	ResizeBindingKey  = "resize_image_key"

	CreateQueueName   = "create_queue"
	CreateConsumerTag = "create_consumer"
	CreateWorkers     = 5
	CreateBindingKey  = "create_image_key"

	UploadHotelImageQueue       = "upload_hotel_image_queue"
	UploadHotelImageConsumerTag = "upload_hotel_image_consumer_tag"
	UploadHotelImageWorkers     = 10
	UploadHotelImageBindingKey  = "upload_hotel_image_binding_key"
)

Variables

View Source
var (
	ErrInvalidUUID            = errors.New("invalid uuid")
	ErrInvalidDeliveryHeaders = errors.New("invalid uuid")
	ErrInternalServerError    = errors.New("internal server error")
	ErrInvalidImageFormat     = errors.New("invalid image format")
)
View Source
var File_app_images_image_proto protoreflect.FileDescriptor

Functions

func NewS3Session

func NewS3Session(cfg *config.Config) *s3.S3

Init new AWS S3 session

func RegisterImageServiceServer

func RegisterImageServiceServer(s *grpc.Server, srv ImageServiceServer)

Types

type AWSS3Client

type AWSS3Client struct {
	// contains filtered or unexported fields
}

func NewAWSStorage

func NewAWSStorage(cfg *config.Config, s3 *s3.S3) AWSS3Client

func (*AWSS3Client) DeleteObject

func (i *AWSS3Client) DeleteObject(ctx context.Context, key string) error

func (*AWSS3Client) GetObject

func (i *AWSS3Client) GetObject(ctx context.Context, key string) (*s3.GetObjectOutput, error)

func (*AWSS3Client) PutObject

func (i *AWSS3Client) PutObject(ctx context.Context, data []byte, fileType string) (string, error)

type AWSStorage

type AWSStorage interface {
	PutObject(ctx context.Context, data []byte, fileType string) (string, error)
	GetObject(ctx context.Context, key string) (*s3.GetObjectOutput, error)
	DeleteObject(ctx context.Context, key string) error
}

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(logger logger.Logger, cfg *config.Config, tracer opentracing.Tracer, pgxPool *pgxpool.Pool, s3 *s3.S3) Application

func (*Application) Run

func (s *Application) Run() error

type Consumer

type Consumer struct {
	Worker    func(ctx context.Context, wg *sync.WaitGroup, messages <-chan amqp.Delivery)
	QueueName string
	Tag       string
	PoolSize  int
}

type ConsumerImpl

type ConsumerImpl struct {
	// contains filtered or unexported fields
}

func NewImageConsumer

func NewImageConsumer(
	logger logger.Logger,
	cfg *config.Config,
	service Service,
	incomingMessages prometheus.Counter,
	successMessages prometheus.Counter,
	errorMessages prometheus.Counter,
) ConsumerImpl

func (*ConsumerImpl) AddConsumer

func (c *ConsumerImpl) AddConsumer(consumer *Consumer)

func (*ConsumerImpl) CloseChannels

func (c *ConsumerImpl) CloseChannels()

CloseChannels close active channels

func (*ConsumerImpl) CreateExchangeAndQueue

func (c *ConsumerImpl) CreateExchangeAndQueue(exchangeName, queueName, bindingKey string) (*amqp.Channel, error)

Consume messages

func (*ConsumerImpl) Dial

func (c *ConsumerImpl) Dial() error

func (*ConsumerImpl) Initialize

func (c *ConsumerImpl) Initialize() error

Initialize consumers

func (*ConsumerImpl) RunConsumers

func (c *ConsumerImpl) RunConsumers(ctx context.Context, cancel context.CancelFunc)

type CreateImageMsg

type CreateImageMsg struct {
	ImageURL   string `json:"image_url"`
	IsUploaded bool   `json:"is_uploaded"`
}

Event message for create image

type GetByIDRequest

type GetByIDRequest struct {
	ImageID string `protobuf:"bytes,1,opt,name=ImageID,proto3" json:"ImageID,omitempty"`
	// contains filtered or unexported fields
}

func (*GetByIDRequest) Descriptor deprecated

func (*GetByIDRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetByIDRequest.ProtoReflect.Descriptor instead.

func (*GetByIDRequest) GetImageID

func (x *GetByIDRequest) GetImageID() 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 {
	Image *Image `protobuf:"bytes,1,opt,name=Image,proto3" json:"Image,omitempty"`
	// contains filtered or unexported fields
}

func (*GetByIDResponse) Descriptor deprecated

func (*GetByIDResponse) Descriptor() ([]byte, []int)

Deprecated: Use GetByIDResponse.ProtoReflect.Descriptor instead.

func (*GetByIDResponse) GetImage

func (x *GetByIDResponse) GetImage() *Image

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 Image

type Image struct {
	CreatedAt  *timestamp.Timestamp `protobuf:"bytes,4,opt,name=CreatedAt,proto3" json:"CreatedAt,omitempty"`
	ImageID    string               `protobuf:"bytes,1,opt,name=ImageID,proto3" json:"ImageID,omitempty"`
	ImageURL   string               `protobuf:"bytes,2,opt,name=ImageURL,proto3" json:"ImageURL,omitempty"`
	IsUploaded bool                 `protobuf:"varint,3,opt,name=IsUploaded,proto3" json:"IsUploaded,omitempty"`
	// contains filtered or unexported fields
}

func (*Image) Descriptor deprecated

func (*Image) Descriptor() ([]byte, []int)

Deprecated: Use Image.ProtoReflect.Descriptor instead.

func (*Image) GetCreatedAt

func (x *Image) GetCreatedAt() *timestamp.Timestamp

func (*Image) GetImageID

func (x *Image) GetImageID() string

func (*Image) GetImageURL

func (x *Image) GetImageURL() string

func (*Image) GetIsUploaded

func (x *Image) GetIsUploaded() bool

func (*Image) ProtoMessage

func (*Image) ProtoMessage()

func (*Image) ProtoReflect

func (x *Image) ProtoReflect() protoreflect.Message

func (*Image) Reset

func (x *Image) Reset()

func (*Image) String

func (x *Image) String() string

type ImageDO

type ImageDO struct {
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
	ImageURL   string    `json:"image_url"`
	ImageID    uuid.UUID `json:"image_id"`
	IsUploaded bool      `json:"is_uploaded"`
}

ImageDO model

func (*ImageDO) ToProto

func (i *ImageDO) ToProto() *Image

type ImageServer

type ImageServer struct {
	// contains filtered or unexported fields
}

func NewImageServer

func NewImageServer(cfg *config.Config, logger logger.Logger, service Service) ImageServer

func (*ImageServer) GetImageByID

func (i *ImageServer) GetImageByID(ctx context.Context, req *GetByIDRequest) (*GetByIDResponse, error)

type ImageServiceClient

type ImageServiceClient interface {
	GetImageByID(ctx context.Context, in *GetByIDRequest, opts ...grpc.CallOption) (*GetByIDResponse, error)
}

ImageServiceClient is the client API for ImageService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

type ImageServiceServer

type ImageServiceServer interface {
	GetImageByID(context.Context, *GetByIDRequest) (*GetByIDResponse, error)
}

ImageServiceServer is the server API for ImageService service.

type ImgResizer

type ImgResizer struct {
	Gift   *gift.GIFT
	Buffer *bytes.Buffer
}

func NewImgResizer

func NewImgResizer(filters ...gift.Filter) *ImgResizer

type Publisher

type Publisher interface {
	CreateExchangeAndQueue(exchange, queueName, bindingKey string) (*amqp.Channel, error)
	Publish(ctx context.Context, exchange, routingKey, contentType string, headers amqp.Table, body []byte) error
}

type PublisherImpl

type PublisherImpl struct {
	// contains filtered or unexported fields
}

func NewPublisher

func NewPublisher(
	cfg *config.Config,
	logger logger.Logger,
	incomingMessages prometheus.Counter,
	successMessages prometheus.Counter,
	errorMessages prometheus.Counter,
) (PublisherImpl, error)

func (*PublisherImpl) CreateExchangeAndQueue

func (p *PublisherImpl) CreateExchangeAndQueue(exchange, queueName, bindingKey string) (*amqp.Channel, error)

func (*PublisherImpl) Publish

func (p *PublisherImpl) Publish(ctx context.Context, exchange, routingKey, contentType string, headers amqp.Table, body []byte) error

Publish message

type Repository

type Repository interface {
	Create(ctx context.Context, msg *ImageDO) (*ImageDO, error)
	GetImageByID(ctx context.Context, imageID uuid.UUID) (*ImageDO, error)
}

type RepositoryImpl

type RepositoryImpl struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(pgxPool *pgxpool.Pool) RepositoryImpl

func (*RepositoryImpl) Create

func (r *RepositoryImpl) Create(ctx context.Context, msg *ImageDO) (*ImageDO, error)

func (*RepositoryImpl) GetImageByID

func (r *RepositoryImpl) GetImageByID(ctx context.Context, imageID uuid.UUID) (*ImageDO, error)

type Service

type Service interface {
	ResizeImage(ctx context.Context, delivery amqp.Delivery) error
	ProcessHotelImage(ctx context.Context, delivery amqp.Delivery) error
	Create(ctx context.Context, delivery amqp.Delivery) error
	GetImageByID(ctx context.Context, imageID uuid.UUID) (*ImageDO, error)
}

type ServiceImpl

type ServiceImpl struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(pgRepo Repository, awsRepo AWSStorage, logger logger.Logger, publisher Publisher) ServiceImpl

func (*ServiceImpl) Create

func (s *ServiceImpl) Create(ctx context.Context, delivery amqp.Delivery) error

func (*ServiceImpl) GetImageByID

func (s *ServiceImpl) GetImageByID(ctx context.Context, imageID uuid.UUID) (*ImageDO, error)

func (*ServiceImpl) ProcessHotelImage

func (s *ServiceImpl) ProcessHotelImage(ctx context.Context, delivery amqp.Delivery) error

func (*ServiceImpl) ResizeImage

func (s *ServiceImpl) ResizeImage(ctx context.Context, delivery amqp.Delivery) error

type UnimplementedImageServiceServer

type UnimplementedImageServiceServer struct {
}

UnimplementedImageServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedImageServiceServer) GetImageByID

type UpdateAvatarMsg

type UpdateAvatarMsg struct {
	ContentType string `json:"content_type"`
	Body        []byte
	UserID      uuid.UUID `json:"user_id"`
}

Event message for upload user avatar

type UpdateHotelImageMsg

type UpdateHotelImageMsg struct {
	Image   string    `json:"image,omitempty"`
	HotelID uuid.UUID `json:"hotel_id"`
}

type UploadImageMsg

type UploadImageMsg struct {
	ImageURL   string    `json:"image_url"`
	ImageID    uuid.UUID `json:"image_id"`
	UserID     uuid.UUID `json:"user_id"`
	IsUploaded bool      `json:"is_uploaded"`
}

Event message for upload image

type UploadedImageMsg

type UploadedImageMsg struct {
	CreatedAt  time.Time `json:"created_at"`
	ImageURL   string    `json:"image_url"`
	ImageID    uuid.UUID `json:"image_id"`
	UserID     uuid.UUID `json:"user_id"`
	IsUploaded bool      `json:"is_uploaded"`
}

Event message for uploaded images

Jump to

Keyboard shortcuts

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