visit
In Golang we could create a microservice skeleton, but for that, we would need some basic structure to work on. Thinking of that we could use an approach to solve that problem as we are used to develop a golang application, which is the Clean Architecture. (if you don’t know what it is, you can see more , I will not add here the benefits or why you should work with it.)
After a long time creating new applications with such structure, manually..
├── config
│ ├── .gitkeep
├── controller
│ ├── .gitkeep
├── domain
│ ├── .gitkeep
├── gateway
│ ├── .gitkeep
├── usecase
│ ├── .gitkeep
├── README.md
├── go.mod
├── go.sum
└── main.go
go get github.com/golangspell/golangspell
cd /path/to/new/project
golangspell init github.com/igor822/spell-test spell-test
Loading Spells ...
Spells loaded!
Rendering template: .gitignore
Rendering template: Dockerfile
Rendering template: README.md
Rendering template: context.got
Rendering template: context_test.got
Rendering template: environment.got
Rendering template: logger.got
Rendering template: version.got
Rendering template: health_controller.got
Rendering template: health_controller_test.got
Rendering template: info_controller.got
Rendering template: info_controller_test.got
Rendering template: router.got
Rendering template: router_test.got
Rendering template: model_health.got
Rendering template: model_info.got
Rendering template: logger.got
Rendering template: main.got
Rendering template: .gitkeep
go: creating new go.mod: module github.com/igor822/spell-test
Application created!
---------------------------------------------------------
To run your application, first build it with the command:
go build
---------------------------------------------------------
Then execute the application with the command (Unix based systems):
./spell-test
Then execute the application with the command (Windows based systems):
spell-test
---------------------------------------------------------
Available endpoints:
//localhost:8080/spell-test/v1/info
//localhost:8080/spell-test/v1/health
---------------------------------------------------------
Find more details on README.md file
Golangspell will provide you already a Dockerfile to containerize your application and also some common tools like
logger
and appcontext
where you can “store your objects” in memory to reuse it, like a repository. Appcontext it's a nice solution to use as a "container" of services inside your application.And simple as you can see in this example, it's done, you don’t need to manually write a bunch of code that you need to configure router, controllers, and even the port that your application will run. For sure it must have several new tools and improvements, like implement some util to connect quickly with NoSQL or MySQL, or even quickly installing and the developer will be able to connect to a database really fast.My idea here is to share a nice tool that I tested and was able to deliver a small service in less than a day, already deploying to production, without issues and allowing me to focus directly in my problem instead to worry about the noise of the standard code we need to write.Also published at