本文整理匯總了Golang中cgt/name/pkg/go-mwclient.Client.Post方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Post方法的具體用法?Golang Client.Post怎麽用?Golang Client.Post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cgt/name/pkg/go-mwclient.Client
的用法示例。
在下文中一共展示了Client.Post方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getPageCategories
// Given an array of page titles, return a mapping from page title to the array
// of categories which the page is a member of.
// If the page doesn't exist, no entry is added to the map.
// If the page has no categories, it will map to nil.
func getPageCategories(pages []string, client *mwclient.Client) map[string][]string {
params := params.Values{
"action": "query",
"titles": mwlib.MakeTitleString(pages),
"prop": "categories",
"cllimit": "max",
"continue": "",
}
json, err := client.Post(params) // Get may fail on long queries.
if err != nil {
fmt.Println(params)
panic(err)
}
pageData, err := json.GetObject("query", "pages")
if err != nil {
panic(err)
}
pageMap := pageData.Map()
result := make(map[string][]string)
for pageId, page := range pageMap {
pageObj, err := page.Object()
if err != nil {
panic(err)
}
title, err := pageObj.GetString("title")
if err != nil {
panic(err)
}
if pageId[0] == '-' {
fmt.Println(title)
fmt.Println("File does not exist, possibly deleted.")
continue
}
categories, err := pageObj.GetObjectArray("categories")
if err != nil {
// Presumably the page has no categories.
result[title] = nil
continue
}
catArray := make([]string, len(categories))
for i := range categories {
catArray[i], err = categories[i].GetString("title")
if err != nil {
panic(err)
}
}
result[title] = catArray
}
return result
}
示例2: catNumFiles
// Examine the specified categories in the Wiki. For each one that actually
// exists, return the number of files that it contains. The result arrays
// give category names (in arbitrary order) and the corresponding count,
// and will have fewer entries than the input array if some categories
// were duplicated or didn't exist.
func catNumFiles(categories []string, client *mwclient.Client) ([]string, []int32) {
params := params.Values{
"action": "query",
"titles": mwlib.MakeTitleString(categories),
"prop": "categoryinfo",
}
json, err := client.Post(params) // Get may fail on long queries.
if err != nil {
panic(err)
}
pages, err := json.GetObject("query", "pages")
if err != nil {
panic(err)
}
pageMap := pages.Map()
var resultCats = make([]string, len(pageMap))
var resultCounts = make([]int32, len(pageMap))
var idx int32 = 0
for pageId, page := range pageMap {
pageObj, err := page.Object()
if err != nil {
panic(err)
}
if pageId[0] != '-' {
resultCats[idx], err = pageObj.GetString("title")
if err != nil {
panic(err)
}
info, err := pageObj.GetObject("categoryinfo")
// An error here means that the category is probably
// empty, so just leave count at 0.
if err == nil {
files, err := info.GetInt64("files")
if err != nil {
panic(err)
}
resultCounts[idx] = int32(files)
}
idx++
}
}
resultCats = resultCats[0:idx]
resultCounts = resultCounts[0:idx]
return resultCats, resultCounts
}