本文整理汇总了Golang中code/google/com/p/rsc/appfs/fs.Context.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Write方法的具体用法?Golang Context.Write怎么用?Golang Context.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/rsc/appfs/fs.Context
的用法示例。
在下文中一共展示了Context.Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: flag
func flag(w http.ResponseWriter, req *http.Request, img string, ctxt *fs.Context) {
if !isImgName(img) && !isTagName(img) {
fmt.Fprintf(w, "Invalid image.\n")
return
}
data, _, _ := ctxt.Read("qr/flag/" + img)
data = append(data, '!')
ctxt.Write("qr/flag/"+img, data)
fmt.Fprintf(w, "Thank you. The image has been reported.\n")
}
示例2: Update
func Update(ctxt *fs.Context, client *http.Client, version string) error {
prefix := strings.Map(func(r rune) rune {
if 'A' <= r && r <= 'Z' {
return r - 'A' + 'a'
}
if 'a' <= r && r <= 'z' || '0' <= r && r <= '9' {
return r
}
return -1
}, version)
label := strings.Map(func(r rune) rune {
if r == ' ' {
return -1
}
return r
}, version)
graphFile := "/issue-dashboard/" + prefix + ".graph"
htmlFile := "/issue-dashboard/" + label
var graph []Point
data, _, err := ctxt.Read(graphFile)
if err == nil {
if err := json.Unmarshal(data, &graph); err != nil {
return fmt.Errorf("unmarshal dashboard graph: %v", err)
}
}
yes, err := issue.Search("go", "open", "label:"+label, false, client)
if err != nil {
return fmt.Errorf("searching for %s issues: %v", version, err)
}
maybe, err := issue.Search("go", "open", "label:"+label+"Maybe", false, client)
if err != nil {
return fmt.Errorf("searching for %sMaybe issues: %v", label, err)
}
graph = append(graph, Point{time.Now(), len(yes), len(maybe)})
data, err = json.Marshal(graph)
if err != nil {
return fmt.Errorf("marshal dashboard graph: %v", err)
}
if err := ctxt.Write(graphFile, data); err != nil {
return fmt.Errorf("writing dashboard graph: %v", err)
}
byDir := map[string][]*issue.Issue{}
for _, p := range append(yes, maybe...) {
dir := p.Summary
if i := strings.Index(dir, ":"); i >= 0 {
dir = dir[:i]
}
if i := strings.Index(dir, ","); i >= 0 {
dir = dir[:i]
}
byDir[dir] = append(byDir[dir], p)
}
var small []Point
now := time.Now()
day := -1
for _, p := range graph {
if p.Maybe == 0 {
continue
}
d := p.Time.Day()
if d != day || now.Sub(p.Time) < 3*24*time.Hour {
day = d
small = append(small, p)
}
}
tmplData := struct {
Version string
Label string
Graph []Point
Issues map[string][]*issue.Issue
}{
Version: version,
Label: label,
Graph: small,
Issues: byDir,
}
var buf bytes.Buffer
tmpl, err := template.New("main").
Funcs(template.FuncMap{
"hasLabel": hasLabel,
"hasStatus": hasStatus,
}).
Parse(dashTemplate)
if err != nil {
return fmt.Errorf("parsing template: %v", err)
}
if err := tmpl.Execute(&buf, &tmplData); err != nil {
return fmt.Errorf("executing template: %v", err)
}
if err := ctxt.Write(htmlFile, buf.Bytes()); err != nil {
return fmt.Errorf("writing html: %v", err)
//.........这里部分代码省略.........