-
Notifications
You must be signed in to change notification settings - Fork 1
/
utilities.go
43 lines (37 loc) · 1.06 KB
/
utilities.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
package utilities
import (
"encoding/json"
"io/ioutil"
"net"
"net/http"
)
//GetIP retrieves the IP address from an http.Request
func GetIP(r *http.Request) string {
if ipProxy := r.Header.Get("X-FORWARDED-FOR"); len(ipProxy) > 0 {
return ipProxy
}
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
return ip
}
//SrvConfiguration represents a container with the server's configuration
type SrvConfiguration struct {
AuthDbConnectionString string `json:"authDb"`
QueueConnectionUrl string `json:"queueUrl"`
StorageDbParams cassandraParameters `json:"storageDb"`
}
type cassandraParameters struct {
ClusterUrls string `json:"clusterUrls"`
Keyspace string `json:"keyspace"`
Username string `json:"username"`
Password string `json:"password"`
}
//LoadJSONConfig returns a SrvConfiguration struct from a json file
func LoadJSONConfig() (*SrvConfiguration, error) {
file, err := ioutil.ReadFile("./config.json")
if err != nil {
return nil, err
}
var config SrvConfiguration
json.Unmarshal(file, &config)
return &config, nil
}