mirror of
https://github.com/hexolan/stocklet.git
synced 2026-03-26 11:41:18 +00:00
feat: go report card
fix: comment and log misspellings
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
An event-driven microservices-based distributed e-commerce example application written in Golang. *(mouthful)*
|
||||
|
||||
[](https://pkg.go.dev/github.com/hexolan/stocklet)
|
||||
[](/LICENSE)
|
||||
[](https://goreportcard.com/report/github.com/hexolan/stocklet)
|
||||
|
||||
## 📘 About
|
||||
|
||||
This project was originally built as an experiment with event-driven architecture. But I hope it can future serve as a beneficial demonstration of utilising the architecture and exemplify the implementation of some other miscellaneous microservice patterns.
|
||||
|
||||
@@ -39,5 +39,5 @@ func applyPostgresMigrations(conf *config.PostgresConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
log.Info().Msg("migrate: succesfully performed postgres migrations")
|
||||
log.Info().Msg("migrate: successfully performed postgres migrations")
|
||||
}
|
||||
|
||||
@@ -65,6 +65,6 @@ func (cfg *SharedConfig) Load() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Config succesfully loaded
|
||||
// Config successfully loaded
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ func (cfg *KafkaConfig) Load() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Comma seperate the kafka brokers
|
||||
// Comma separate the kafka brokers
|
||||
cfg.Brokers = strings.Split(brokersOpt, ",")
|
||||
|
||||
// Config options were succesfully loaded
|
||||
// Config options were successfully loaded
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,6 +28,6 @@ func (cfg *OtelConfig) Load() error {
|
||||
cfg.CollectorGrpc = collectorGrpc
|
||||
}
|
||||
|
||||
// Succesfully loaded config properties
|
||||
// Successfully loaded config properties
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -80,6 +80,6 @@ func (cfg *PostgresConfig) Load() error {
|
||||
cfg.Database = opt
|
||||
}
|
||||
|
||||
// Config properties succesfully loaded
|
||||
// Config properties successfully loaded
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ type AuthService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Allows implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Allows implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
SetPassword(ctx context.Context, userId string, password string) error
|
||||
VerifyPassword(ctx context.Context, userId string, password string) (bool, error)
|
||||
@@ -50,7 +50,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ func (c *kafkaController) Start() {
|
||||
case messaging.User_State_Deleted_Topic:
|
||||
c.consumeUserDeletedEventTopic(ft)
|
||||
default:
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic")
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: received records from unexpected topic")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func (c *kafkaController) Stop() {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeUserDeletedEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
|
||||
@@ -95,7 +95,7 @@ func (c *kafkaController) Start() {
|
||||
case messaging.Payment_Processing_Topic:
|
||||
c.consumePaymentProcessedEventTopic(ft)
|
||||
default:
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic")
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: received records from unexpected topic")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (c *kafkaController) Stop() {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeProductPriceQuoteEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -125,7 +125,7 @@ func (c *kafkaController) consumeProductPriceQuoteEventTopic(ft kgo.FetchTopic)
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeStockReservationEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -143,7 +143,7 @@ func (c *kafkaController) consumeStockReservationEventTopic(ft kgo.FetchTopic) {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -161,7 +161,7 @@ func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic)
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumePaymentProcessedEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
|
||||
@@ -108,7 +108,7 @@ func (c postgresController) CreateOrder(ctx context.Context, orderObj *pb.Order)
|
||||
// Create records for any order items
|
||||
err = c.createOrderItems(ctx, tx, newOrder.Id, newOrder.Items)
|
||||
if err != nil {
|
||||
// The deffered rollback will be called (so the transaction will not be commited)
|
||||
// The deffered rollback will be called (so the transaction will not be committed)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ type OrderService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Flexibility for implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
GetOrder(ctx context.Context, orderId string) (*pb.Order, error)
|
||||
GetCustomerOrders(ctx context.Context, customerId string) ([]*pb.Order, error)
|
||||
@@ -52,7 +52,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ func (c *kafkaController) Start() {
|
||||
case messaging.Shipping_Shipment_Allocation_Topic:
|
||||
c.consumeShipmentAllocationEventTopic(ft)
|
||||
default:
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic")
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: received records from unexpected topic")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func (c *kafkaController) Stop() {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeUserCreatedEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -122,7 +122,7 @@ func (c *kafkaController) consumeUserCreatedEventTopic(ft kgo.FetchTopic) {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
|
||||
@@ -313,7 +313,7 @@ func (c postgresController) PaymentForOrder(ctx context.Context, orderId string,
|
||||
evtTopic string
|
||||
)
|
||||
if transaction != nil {
|
||||
// Succesful
|
||||
// Successful
|
||||
evt, evtTopic, err = payment.PreparePaymentProcessedEvent_Success(transaction)
|
||||
} else {
|
||||
// Failure
|
||||
@@ -321,7 +321,7 @@ func (c postgresController) PaymentForOrder(ctx context.Context, orderId string,
|
||||
evt, evtTopic, err = payment.PreparePaymentProcessedEvent_Failure(orderId, customerId, amount)
|
||||
}
|
||||
|
||||
// Ensure the event was prepared succesfully
|
||||
// Ensure the event was prepared successfully
|
||||
if err != nil {
|
||||
return errors.WrapServiceError(errors.ErrCodeService, "failed to create event", err)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ type PaymentService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Flexibility for implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
GetBalance(ctx context.Context, customerId string) (*pb.CustomerBalance, error)
|
||||
GetTransaction(ctx context.Context, transactionId string) (*pb.Transaction, error)
|
||||
@@ -52,7 +52,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func (c *kafkaController) Start() {
|
||||
case messaging.Order_State_Created_Topic:
|
||||
c.consumeOrderCreatedEventTopic(ft)
|
||||
default:
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic")
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: received records from unexpected topic")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (c *kafkaController) Stop() {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeOrderCreatedEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
|
||||
@@ -38,7 +38,7 @@ type ProductService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Flexibility for implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
GetProduct(ctx context.Context, productId string) (*pb.Product, error)
|
||||
GetProducts(ctx context.Context) ([]*pb.Product, error)
|
||||
@@ -50,7 +50,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func (c *kafkaController) Start() {
|
||||
case messaging.Payment_Processing_Topic:
|
||||
c.consumePaymentProcessedEventTopic(ft)
|
||||
default:
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic")
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: received records from unexpected topic")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (c *kafkaController) Stop() {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeStockReservationEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -117,7 +117,7 @@ func (c *kafkaController) consumeStockReservationEventTopic(ft kgo.FetchTopic) {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumePaymentProcessedEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
|
||||
@@ -38,7 +38,7 @@ type ShippingService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Flexibility for implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
GetShipment(ctx context.Context, shipmentId string) (*pb.Shipment, error)
|
||||
GetShipmentItems(ctx context.Context, shipmentId string) ([]*pb.ShipmentItem, error)
|
||||
@@ -48,7 +48,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ type UserService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Flexibility for implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
GetUser(ctx context.Context, userId string) (*pb.User, error)
|
||||
|
||||
@@ -47,7 +47,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ func (c *kafkaController) Start() {
|
||||
case messaging.Payment_Processing_Topic:
|
||||
c.consumePaymentProcessedEventTopic(ft)
|
||||
default:
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: recieved records from unexpected topic")
|
||||
log.Warn().Str("topic", ft.Topic).Msg("consumer: received records from unexpected topic")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (c *kafkaController) Stop() {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeOrderPendingEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -125,7 +125,7 @@ func (c *kafkaController) consumeOrderPendingEventTopic(ft kgo.FetchTopic) {
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
@@ -143,7 +143,7 @@ func (c *kafkaController) consumeShipmentAllocationEventTopic(ft kgo.FetchTopic)
|
||||
}
|
||||
|
||||
func (c *kafkaController) consumePaymentProcessedEventTopic(ft kgo.FetchTopic) {
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: recieved records from topic")
|
||||
log.Info().Str("topic", ft.Topic).Msg("consumer: received records from topic")
|
||||
|
||||
// Process each message from the topic
|
||||
ft.EachRecord(func(record *kgo.Record) {
|
||||
|
||||
@@ -38,7 +38,7 @@ type WarehouseService struct {
|
||||
}
|
||||
|
||||
// Interface for database methods
|
||||
// Flexibility for implementing seperate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
// Flexibility for implementing separate controllers for different databases (e.g. Postgres, MongoDB, etc)
|
||||
type StorageController interface {
|
||||
GetProductStock(ctx context.Context, productId string) (*pb.ProductStock, error)
|
||||
GetReservation(ctx context.Context, reservationId string) (*pb.Reservation, error)
|
||||
@@ -51,7 +51,7 @@ type StorageController interface {
|
||||
}
|
||||
|
||||
// Interface for event consumption
|
||||
// Flexibility for seperate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
// Flexibility for separate controllers for different messaging systems (e.g. Kafka, NATS, etc)
|
||||
type ConsumerController interface {
|
||||
messaging.ConsumerController
|
||||
|
||||
|
||||
Reference in New Issue
Block a user