battlenet
1.0.0
用於從 Blizzard 的 Battle.net API 檢索資料的 Golang 函式庫。
需要 Go 1.12 或更高版本。
$ go get github.com/munsy/battlenet
package main
import (
"flag"
"fmt"
"net/http"
"time"
"github.com/munsy/battlenet"
)
var tokenFlag = flag.String("t", "", "Battle.net API token (required).")
func main() {
flag.Parse()
if *tokenFlag == "" {
fmt.Println("No token provided.")
return
}
// Create settings for the client. This is not required, but
// is necessary for non-default settings.
settings := &battlenet.Settings{
Client: &http.Client{Timeout: (10 * time.Second)},
Locale: battlenet.Locale.AmericanEnglish,
Region: battlenet.Regions.US,
}
// Create a new client for accessing the Battle.net Account API.
// There are also clients for Diablo III, Starcraft II, and WoW.
client, err := battlenet.AccountClient(settings, *tokenFlag)
if nil != err {
panic(err)
}
// Make a request. Each method corresponds to a Battle.net endpoint.
response, err := client.BattleID()
if nil != err {
panic(err)
}
// Get the underlying data. You can also see the endpoint that was called,
// as well as your quota usage.
bid := response.Data
fmt.Printf("ID: %dn", bid.ID)
fmt.Printf("BattleTag: %sn", bid.BattleTag)
}$ go build -o account.exe $ ./account.exe -t $YOUR_API_TOKEN_HERE ID: 12345654321 BattleTag: Munsy#78910
暗黑破壞神 III、星海爭霸 II 和魔獸世界的其他範例可以在範例包中找到。
請將所有錯誤報告作為問題提交。本節將來將更新,提供更全面的指南來提交有用的錯誤報告和/或錯誤修復。
測試是目前最需要的
以拉取請求的形式提交貢獻
GoBattleNet 根據 MIT 許可證獲得許可。請參閱許可證以取得完整的許可證文字。