Web Service with Go and Go-Web
Go-Web reduces the need for “repetitive” tasks like explicitly binding routes, actions, and middleware; while not problematic per se, programmers may want to adopt “ready-to-use” solutions, for instances if they want easily build complex services, aiming at a reduced “productive lag”.
By following this principle, Go-Web reduces the need for “repetitive” tasks like explicitly binding routes, actions, and middleware; while not problematic per se, programmers may want to adopt “ready-to-use” solutions, for instances if they want easily build complex services, aiming at a reduced “productive lag”.
SEE ALSO: How Curve is getting ahead with Golang
You can install Go-Web as follows :
If you’re using Visual Studio Code you can install Go-Web framework with its specific extension: https://marketplace.visualstudio.com/items?itemName=Roberto.go-web
Go-Web uses the so-called kernel in conjunction with the Service Container, file routes.yml and dependency gorilla/mux to build the map that routes each incoming HTTP request to the appropriate method of a specific controller: after the initialization process, requests will be processed by the Go-Web black box. Figure 1 illustrates this process.
The startup process is executed once and uses reflection so that the service container can inject relevant bits of code into controllers; this approach allows controllers to access any service defined in the service container, like databases or log systems, reducing redundant (“boilerplate”) code.
While resolving a route is done by gorilla/mux, the execution of the code associated with the same route is performed (or tunneled) by the Service Container, which injects dependencies into the end-point controller: before going through a controller, a request may be processed by one or more middleware.
This workflow can be easily understood by looking at figure 2.
After being received by the Go-Web “black box”, a request may follow workflow starting in entry points A or B, figure 2.
The service container (fig. 3) is the tool that manages class dependencies and performs dependency injection through DIG.
As depicted in figure 3, the service container will register other services if correctly linked in the kernel: the process requires the implementation of such new services and further “registration” by adding them to Services array defined in Go-Web kernel
Development environment setup
Go-Web provides a docker-compose.yml file that allows developers to easily set up a new development environment: this requires both Docker  and Docker-compose  installed on the development system.
The docker-compose.yml defines several services, i.e. it is configured for providing instances of MySQL, Redis, MongoDB, and ElasticSearch; if needed, instances of other services may be added by modifying the docker-compose.yml file.