-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
57 lines (47 loc) · 1.29 KB
/
app.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
package main
import (
"net/http"
"github.com/auth-server-go/controller"
"encoding/json"
"bytes"
"io/ioutil"
"log"
"fmt"
)
const LOGIN_URL = "/login"
const SIGNUP_URL = "/signup"
const PROFILE_URL = "/register"
const SERVER_PORT = ":8085"
func register_service(){
//Encode the data
postBody, _ := json.Marshal(map[string]string{
"ServiceName": "Ronit1",
"ServiceUrl": "localhost" + SERVER_PORT,
})
responseBody := bytes.NewBuffer(postBody)
//Leverage Go's HTTP Post function to make request
resp, err := http.Post("http://localhost:8081/lb/register", "application/json", responseBody)
//Handle Error
if err != nil {
log.Fatalf("An Error Occured %v", err)
}
defer resp.Body.Close()
//Read the response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
sb := string(body)
fmt.Printf(sb)
fmt.Printf("hello registered service")
}
func main() {
go register_service()
sign_up_handler := http.HandlerFunc(controller.Handle_sign_up_request)
login_handler := http.HandlerFunc(controller.Handle_login_request)
profile_handler := http.HandlerFunc(controller.Handle_Profile_request)
http.Handle(LOGIN_URL, login_handler)
http.Handle(SIGNUP_URL, sign_up_handler)
http.Handle(PROFILE_URL, profile_handler)
http.ListenAndServe(SERVER_PORT, nil)
}