本文整理匯總了Golang中cgt/name/pkg/go-mwclient.Client.GetPageByName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.GetPageByName方法的具體用法?Golang Client.GetPageByName怎麽用?Golang Client.GetPageByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cgt/name/pkg/go-mwclient.Client
的用法示例。
在下文中一共展示了Client.GetPageByName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addCategory
func addCategory(page string, category string, client *mwclient.Client) {
// There's a small chance that saving a page may fail due to
// an edit conflict or other transient error. Try up to 3
// times before giving up.
var saveError error
for i := 0; i < 3; i++ {
text, timestamp, err := client.GetPageByName(page)
if err != nil {
panic(fmt.Sprintf("%v %v", page, err))
}
// Add the category at the end of the text, since categories
// are supposed to be at the end anyway. A previous version
// tried to add after the last existing category, but that
// can fail when the text contains comments.
last := len(text)
text = text[0:last] + "\n[[" + category + "]]"
editcfg := map[string]string{
"action": "edit",
"title": page,
"text": text,
"summary": "added [[" + category + "]]",
"minor": "",
"bot": "",
"basetimestamp": timestamp,
}
saveError = client.Edit(editcfg)
if saveError == nil {
break
}
}
if saveError != nil {
panic(fmt.Sprintf("Failed to save %v %v", page, saveError))
}
}
示例2: createGallery
// Create a gallery showing all the files with warnings. Page must already
// exist and will be replaced.
func (warnings warnings) createGallery(gallery string, client *mwclient.Client) {
var saveError error
sort.Sort(warnings)
for i := 0; i < 3; i++ {
_, timestamp, err := client.GetPageByName(gallery)
if err != nil {
panic(fmt.Sprintf("%v %v", gallery, err))
}
// Blank the page and create a fresh gallery
var buffer bytes.Buffer
buffer.WriteString("<gallery>\n")
for w := range warnings {
buffer.WriteString(warnings[w].title)
buffer.WriteByte('|')
if len(warnings[w].warning) > 200 {
buffer.WriteString(warnings[w].warning[0:200])
buffer.WriteString("...")
} else {
buffer.WriteString(warnings[w].warning)
}
buffer.WriteByte('\n')
}
buffer.WriteString("</gallery>")
editcfg := map[string]string{
"action": "edit",
"title": gallery,
"text": buffer.String(),
"bot": "",
"basetimestamp": timestamp,
}
saveError = client.Edit(editcfg)
if saveError == nil {
break
}
}
if saveError != nil {
panic(fmt.Sprintf("Failed to save %v %v", gallery, saveError))
}
}