REST Microservice developed in Go. Works with following struct:
type Product struct {
ID int `json:"id" storm:"id,increment=3"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Price float32 `json:"price" validate:"required,gt=0"`
SKU string `json:"sku" validate:"required,sku"`
CreatedOn string `json:"-"`
UpdatedOn string `json:"-"`
DeletedOn string `json:"-"`
}
- Gorilla/mux for routing
- Storm for DB storage
- Validator for data validation
- AMQP for RabbitMQ integration
- Logrus for logging
curl localhost:9090
curl localhost:9090/{id}
curl localhost:9090 -X POST -d `{"name":"New product", "price":3.22, "sku":"abc-abcd-abcde"...}`
curl localhost:9090/{id} -X PUT -d `{"name":"Updated", "price":1.99, "sku":"abc-abcd-abcde"...}`
curl localhost:9090/{id} -X DELETE
You can run the service with the following command
go run main.go -rabbitmq
This will enable RabbitMQ service and will run both the consumer and producer.
- Service uses the following data model:
type User struct {
ID int `json:"id" storm:"id,increment=1"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Gender string `json:"gender"`
IPAddress string `json:"ip_address"`
CreatedAt time.Time `json:"created_at"`
}
- Producer will publish the message to queue every 10 seconds.
- The message is fetched from mock API.
- Consumer will consume the message and insert the user into BoltDB database.
curl localhost:9090/users