-
Notifications
You must be signed in to change notification settings - Fork 0
/
async_service_call_v1.go
60 lines (46 loc) · 1.1 KB
/
async_service_call_v1.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
//to make web requests
"net/http"
//read the response from call
//unmarshall the XML response
"time"
)
func main() {
gihubUserName := []string{
"SamsadSajid",
"go",
"elixir",
"google",
}
start := time.Now()
for _, name := range gihubUserName {
resp, _ := http.Get("https://api.github.com/users/" + name)
//close the connection
defer resp.Body.Close()
// fmt.Println(resp)
// this should be done carefully because
// if data is big it can blow up the system but
// in this example data is small so we can read that in single byte stream
body, _ := ioutil.ReadAll(resp.Body)
gihubUserInfo := GithubUserInfo{}
json.Unmarshal(body, &gihubUserInfo)
fmt.Println(
"Login Name: = ", gihubUserInfo.Login,
"Followers:=", gihubUserInfo.Followers,
"Email:=", gihubUserInfo.Email,
"Bio:=", gihubUserInfo.Bio,
)
timeTakenForCall := time.Since(start)
fmt.Println("Execution time is: ", timeTakenForCall)
}
}
type GithubUserInfo struct {
Login string
Followers int
Email string
Bio string
}