Skip to content

Commit 8619e43

Browse files
committed
Fixed Sequential execution
1 parent 3e90207 commit 8619e43

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

githubapi/githubapi.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,17 @@ func GetReposData(username string, noOfRepos int) []ReposInfoJson {
119119
if err != nil {
120120
log.Fatal(err)
121121
}
122-
searchResult := responseToRepoData(bodyJson) //Unmarshall ReposJson to ReposInfoJsonArray.
122+
searchResult := responseToRepoData(bodyJson) //Unmarshall ReposJson to []ReposInfoJson.
123123
result = append(result, searchResult...) //Append ReposJson after changing each Page query.
124124
}
125125
return result
126126
}
127127

128-
func Fetch(username string) userCollection {
128+
func Fetch(username string) []byte {
129129
accountData := GetUserData(username)
130130
repoData := GetReposData(username, accountData.Public_repos)
131+
marshalToStruct := (userCollection{accountData, repoData})
131132

132-
return (userCollection{accountData, repoData})
133-
}
134-
135-
func MarshalFetchData(data userCollection) []byte {
136-
accountByte, _ := json.MarshalIndent(data, " ", " ")
137-
return accountByte
133+
resultByte, _ := json.MarshalIndent(marshalToStruct, " ", " ")
134+
return resultByte
138135
}

start.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
func sequence(usernames []string) {
1010

1111
for _, username := range usernames {
12-
resultJson := githubapi.Fetch(username)
13-
resultByte := githubapi.MarshalFetchData(resultJson)
12+
resultByte := githubapi.Fetch(username)
1413
io.WriteToFile(username, resultByte)
1514
}
1615
}
@@ -36,9 +35,7 @@ func concurrently(usernames []string) {
3635

3736
func conFetch(username string, dataToFile chan map[string][]byte, wg *sync.WaitGroup) {
3837

39-
resultJson := githubapi.Fetch(username)
40-
resultByte := githubapi.MarshalFetchData(resultJson)
41-
38+
resultByte := githubapi.Fetch(username)
4239
dataToChannel := make(map[string][]byte)
4340
dataToChannel[username] = resultByte
4441
dataToFile <- dataToChannel

0 commit comments

Comments
 (0)