Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chai2010/ghutil
ghutil
https://github.com/chai2010/ghutil
Last synced: 3 months ago
JSON representation
ghutil
- Host: GitHub
- URL: https://github.com/chai2010/ghutil
- Owner: chai2010
- License: bsd-3-clause
- Created: 2023-05-12T03:35:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-05-12T03:50:21.000Z (over 1 year ago)
- Last Synced: 2024-10-06T01:18:20.364Z (3 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 用 Go 获取 Github 常用信息
[hello.go](hello.go) 例子:
```go
package mainimport (
"context"
"flag"
"fmt"
"os""github.com/chai2010/ghutil"
)var (
flagUserName = flag.String("u", "chai2010", "set user name")
)func main() {
flag.Parse()c := ghutil.NewGHClient(&ghutil.GHOptions{
Token: os.Getenv("GITHUB_ACCESS_TOKEN"),
})
repos, err := c.GetRepositories(context.Background(), *flagUserName)
if err != nil {
panic(err)
}var starCount int
var forkCount int
for _, repo := range repos {
starCount += *repo.StargazersCount
forkCount += *repo.ForksCount
}fmt.Printf("%s/{*}:StargazersCount: %d\n", *flagUserName, starCount)
fmt.Printf("%s/{*}:ForksCount: %d\n", *flagUserName, forkCount)
}
```设置好 `GITHUB_ACCESS_TOKEN` 环境变量, 然后执行:
```
$ go run hello.go -u=chai2010
chai2010/{*}:StargazersCount: 25283
chai2010/{*}:ForksCount: 3978$ go run hello.go -u=KusionStack
KusionStack/{*}:StargazersCount: 1206
KusionStack/{*}:ForksCount: 200
```