Made a basic date service with go-kit-CLI using gorilla mux router to get the current date, status of the service and validate a date.
- Download the project in your GOPATH.
- cd inside the folder and run
docker-compose up
using thedocker-compose.yml
file or usinggo run hello/cmd/main.go
hello/
|---cmd/
|------service/
|----------server.go Wire the service.
|----------server_gen.go Also wire the service.
|------main.go Runs the service
|---pkg/
|------endpoints/
|----------endpoint.go The endpoint logic along with structures for request and reponse.
|----------endpoint_gen.go This will wire the endpoints.
|----------middleware.go Endpoint middleware
|------http/
|----------handler.go Transport logic encode/decode data and gorilla mux request reponse routing of the service.
|----------handler_gen.go This will wire the transport.
|------io/
|----------io.go The input output structs.
|------service/
|----------middleware.go The service middleware.
|----------service.go Business logic.
- Use
kit new service hello
to make a service named hello. - Edit the business logic file (
hello/pkg/service/service.go
) with the methods in your service interface. - To generate the service with gorilla and default middleware use
kit g s hello -w --gorilla
- A basic service that does not handle request and reponse can be run right now using
go run hello/cmd/main.go
- NOTE: Our service runs at port 8081 and not on the default gorilla mux port 8080.
- Now implement our services in
hello/pkg/service/service.go
file. - One can write the test in the same service folder for the business logic, right now.
- Then edit
hello/pkg/endpoint/endpoint.go
for the request reponse structs. - Then edit
hello/pkg/http/handler.go
for the encode and decode. - Edit the requests routed by the gorilla mux router in
hello/pkg/http/handler.go
- Correct any errors if they arise.
- Make a dockerfile using
kit g d
- We are done just run the service using
docker-compose up