-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
65 lines (51 loc) · 1.81 KB
/
config.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package config
import (
"encoding/json"
"io/ioutil"
"os"
commonconf "github.com/Microkubes/microservice-tools/config"
"github.com/Microkubes/microservice-tools/gateway"
)
// Config holds the microservice full configuration.
type Config struct {
// Microservice is a gateway.Microservice configuration for self-registration and service config.
Microservice gateway.MicroserviceConfig `json:"microservice"`
// Database holds the database configuration
Database *commonconf.DBConfig `json:"database"`
// GatewayURL is the URL of the gateway (proxy).
GatewayURL string `json:"gatewayUrl"`
// GatewayAdminURL is the administration URL of the API Gateway. Used for purposes of registration of a
// microservice with the API gateway.
GatewayAdminURL string `json:"gatewayAdminUrl"`
// SystemKey holds the path to the system key which is private RSA key
SystemKey string `json:"systemKey"`
// ServiceKey holds the path to the service key
ServiceKey string `json:"serviceKey"`
// ServiceCert holds the path to the service cert
ServiceCert string `json:"serviceCert"`
// Services is a map of <service-name>:<service base URL>. For example,
// "user-microservice": "http://kong.gateway:8001/user"
Services map[string]string `json:"services"`
// Client is a map of <client-name>:<url>
// "redirect-from-login": "http://client-root-url"
Client map[string]string `json:"client"`
}
// LoadConfig loads a Config from a configuration JSON file.
func LoadConfig(confFile string) (*Config, error) {
if confFile == "" {
confFile = os.Getenv("SERVICE_CONFIG_FILE")
if confFile == "" {
confFile = "config.json"
}
}
confBytes, err := ioutil.ReadFile(confFile)
if err != nil {
return nil, err
}
config := &Config{}
err = json.Unmarshal(confBytes, config)
if err != nil {
return nil, err
}
return config, nil
}