Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 257212e

Browse files
committed
fix json unmarshal error
1 parent 463ba81 commit 257212e

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package main
22

33
import "fmt"
44

5-
func GetUser(username string) (res map[string]interface{}, err error) {
5+
func GetUser(username string) (res []interface{}, err error) {
66
return Get(fmt.Sprintf("users/%s", username))
77
}
88

9-
func GetRepos(username string) (res map[string]interface{}, err error) {
9+
func GetRepos(username string) (res []interface{}, err error) {
1010
return Get(fmt.Sprintf("users/%s/repos", username))
1111
}
1212

13-
func GetRepo(username string, repo string) (res map[string]interface{}, err error) {
13+
func GetRepo(username string, repo string) (res []interface{}, err error) {
1414
return Get(fmt.Sprintf("repos/%s/%s", username, repo))
1515
}
1616

17-
func GetLanguages(username string, repo string) (res map[string]interface{}, err error) {
17+
func GetLanguages(username string, repo string) (res []interface{}, err error) {
1818
return Get(fmt.Sprintf("repos/%s/%s/languages", username, repo))
1919
}

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"github.com/sirupsen/logrus"
65
)
76

@@ -11,5 +10,4 @@ func main() {
1110

1211
tokenList = GetTokenFromEnv()
1312
ValidateToken()
14-
fmt.Println(GetRepos("zmh-program"))
1513
}

utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func ScaleConvert(n float64, useSmallScale bool) string {
4747
return fmt.Sprintf("%.1f%s", n, scaleUnits[idx])
4848
}
4949

50-
func Get(uri string) (res map[string]interface{}, err error) {
50+
func Get(uri string) (res []interface{}, err error) {
5151
req, err := http.NewRequest("GET", "https://api.github.com/"+uri, nil)
5252
if err != nil {
5353
return nil, err
@@ -69,7 +69,7 @@ func Get(uri string) (res map[string]interface{}, err error) {
6969
}
7070
}(resp.Body)
7171

72-
var data map[string]interface{}
72+
var data []interface{}
7373
err = json.NewDecoder(resp.Body).Decode(&data)
7474
if err != nil {
7575
return nil, err

0 commit comments

Comments
 (0)