go-microservice

module
v0.0.0-...-f0a25a6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT

README

go-microservice

An attempt to learn microservices using Golang.

Refs:
Part-1:
  • Build a very basic http server using go
  • Add different handlefuncs for different paths
  • Add some logging and write to the response
  • Handle error and return appropriate code for that
  • Run the server using go run main.go
  • Use curl for query like curl -v -d 'Request' localhost:9090, curl -v localhost:9090/goodbye, curl -v localhost:9090
Part-2:
  • Add handler package
  • Build custom handlers
  • Use logger wih specific info
  • Define custom http server
  • Implement graceful shutdown
  • Add ReadTimeout, IdleTimeout, WriteTimeout
Part-3:
  • Add product package
  • Introduce RESTful services
  • Add JSON encoding/ JSON serializing
  • Add filtering to HTTP requests
  • Add http get request handler
  • Add Graceful shutdown
Part-4:
  • Add handlers package
  • Add http PUT and POST request handlers
  • Tested with commands like: curl -v localhost:9090/1 -XPUT -d '{"id":1, "name":"tea", "description":"a nice cup of tea"}', curl -v localhost:9090 -X POST -d '{"name": "Water"}'
Part-5:
  • Add Gorilla MUX router
  • Refactor previous code and replace default HTTP router with Gorilla MUX
  • Add Middleware to PUT and POST methods
  • Handle JSON deserializing from Middleware
Part-6:
  • Use Go Validators
  • Add Json validation for product fields in Middleware
  • Test validation with simple unit test
part-7:
  • Use Swagger for documentation
  • Use Runtime Middleware
  • Add Redoc for visualizing the documentation
  • You can now see well organized documentation on http://localhost:9090/docs by running the program
  • Refactor the code
part-8:
  • Create auto-generated client through Swagger
  • To generate client: swagger generate client -f ../swagger.yaml -A product-api

Resources:

Directories

Path Synopsis
currency module
handlers
Package classification of Product API
Package classification of Product API

Jump to

Keyboard shortcuts

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