-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
41 lines (34 loc) · 1 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package configuration
import (
"encoding/json"
"fmt"
"os"
"github.com/PacktPublishing/Cloud-Native-programming-with-Golang/chapter03/myevents/src/lib/persistence/dblayer"
)
var (
DBTypeDefault = dblayer.DBTYPE("mongodb")
DBConnectionDefault = "mongodb://127.0.0.1"
RestfulEPDefault = "localhost:8181"
RestfulTLSEPDefault = "localhost:9191"
)
type ServiceConfig struct {
Databasetype dblayer.DBTYPE `json:"databasetype"`
DBConnection string `json:"dbconnection"`
RestfulEndpoint string `json:"restfulapi_endpoint"`
RestfulTLSEndPint string `json:"restfulapi-tlsendpoint"`
}
func ExtractConfiguration(filename string) (ServiceConfig, error) {
conf := ServiceConfig{
DBTypeDefault,
DBConnectionDefault,
RestfulEPDefault,
RestfulTLSEPDefault,
}
file, err := os.Open(filename)
if err != nil {
fmt.Println("Configuration file not found. Continuing with default values.")
return conf, err
}
err = json.NewDecoder(file).Decode(&conf)
return conf, err
}