Go Microservice Part II - Application Configuration
By ski11up.com
In the previous blog post, Go MVC Part I - Overview we have seen the overall structure of contacts application.
Let’s start with writing the application configuration using Viper
.
Viper
After creating the folder structure as mentioned in the previous post, we need to import the Viper
package for writing the application configuration.
From the project root folder run the below command.
$ go get github.com/spf13/viper
Application Config
Create a config.yml
in the root directory and save the below information, this is your application server PORT
.
server:
port: ':7000'
Under the project root directory create a config/
folder and create a file as config.go
and paste the below code.
1
2
3
4
5
6
7
8
package config
type Configurations struct { (1)
Server ServerConfig
}
type ServerConfig struct { (2)
Port string
}
1 | defining a struct which will store the overall configuration |
2 | defining ServerConfig struct based on the main struct Configurations |
This completes the configuration part, lets move forward, and start with the application code.
Next
Go to Go MVC Part III to get started with the application code.