-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (43 loc) · 1.41 KB
/
main.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
package main
import (
"fmt"
"net/http"
"io/ioutil"
"github.com/tkanos/gonfig"
)
type Configuration struct {
Port int
ServiceA string
ServiceB string
}
func main() {
configuration := Configuration{}
conferr := gonfig.GetConf("config/config.json", &configuration)
if conferr != nil {
fmt.Println("Failed to read config file")
}
fmt.Printf("Starting the frontend application... 1.3 port : %d",configuration.Port)
servicea := "no results"
serviceb := "no results"
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
response, err := http.Get(configuration.ServiceA)
if err != nil {
fmt.Printf("The HTTP request failed servicea with error %s\n", err)
} else {
data, _ := ioutil.ReadAll(response.Body)
servicea = string(data)
}
response1, err1 := http.Get(configuration.ServiceB)
if err1 != nil {
fmt.Printf("The HTTP request failed serviceb with error %s\n", err)
} else {
data1, _ := ioutil.ReadAll(response1.Body)
serviceb = string(data1)
}
fmt.Fprintf(w, "<html><body>")
fmt.Fprintf(w, "first service: %s <br />",servicea)
fmt.Fprintf(w, "second service: %s <br />",serviceb)
fmt.Fprintf(w, "</body></html>")
})
http.ListenAndServe(fmt.Sprintf(":%d",configuration.Port), nil)
}