• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang fs.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/amrhassan/rsc/appfs/fs.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Context类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: loadPost

func loadPost(c *fs.Context, name string, req *http.Request) (meta *PostData, article string, err error) {
	meta = &PostData{
		Name:       name,
		Title:      "TITLE HERE",
		PlusAuthor: plusRsc,
		PlusAPIKey: plusKey,
		HostURL:    hostURL(req),
	}

	art, fi, err := c.Read("blog/post/" + name)
	if err != nil {
		return nil, "", err
	}
	if bytes.HasPrefix(art, []byte("{\n")) {
		i := bytes.Index(art, []byte("\n}\n"))
		if i < 0 {
			panic("cannot find end of json metadata")
		}
		hdr, rest := art[:i+3], art[i+3:]
		if err := json.Unmarshal(hdr, meta); err != nil {
			panic(fmt.Sprintf("loading %s: %s", name, err))
		}
		art = rest
	}
	meta.FileModTime = fi.ModTime
	meta.FileSize = fi.Size

	return meta, replacer.Replace(string(art)), nil
}
开发者ID:amrhassan,项目名称:rsc,代码行数:29,代码来源:post.go


示例2: loadSize

func loadSize(ctxt *fs.Context, name string, max int) *image.RGBA {
	data, _, err := ctxt.Read("qr/upload/" + name + ".png")
	if err != nil {
		panic(err)
	}
	i, _, err := image.Decode(bytes.NewBuffer(data))
	if err != nil {
		panic(err)
	}
	b := i.Bounds()
	dx, dy := max, max
	if b.Dx() > b.Dy() {
		dy = b.Dy() * dx / b.Dx()
	} else {
		dx = b.Dx() * dy / b.Dy()
	}
	var irgba *image.RGBA
	switch i := i.(type) {
	case *image.RGBA:
		irgba = resize.ResizeRGBA(i, i.Bounds(), dx, dy)
	case *image.NRGBA:
		irgba = resize.ResizeNRGBA(i, i.Bounds(), dx, dy)
	}
	return irgba
}
开发者ID:amrhassan,项目名称:rsc,代码行数:25,代码来源:play.go


示例3: 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")
}
开发者ID:amrhassan,项目名称:rsc,代码行数:11,代码来源:play.go


示例4: mainTemplate

func mainTemplate(c *fs.Context) *template.Template {
	t := template.New("main")
	t.Funcs(funcMap)

	main, _, err := c.Read("blog/main.html")
	if err != nil {
		panic(err)
	}
	style, _, _ := c.Read("blog/style.html")
	main = append(main, style...)
	_, err = t.Parse(string(main))
	if err != nil {
		panic(err)
	}
	return t
}
开发者ID:amrhassan,项目名称:rsc,代码行数:16,代码来源:post.go


示例5: runTemplate

func runTemplate(c *fs.Context, w http.ResponseWriter, name string, data interface{}) {
	t := template.New("main")

	main, _, err := c.Read(name)
	if err != nil {
		panic(err)
	}
	style, _, _ := c.Read("style.html")
	main = append(main, style...)
	_, err = t.Parse(string(main))
	if err != nil {
		panic(err)
	}

	var buf bytes.Buffer
	if err := t.Execute(&buf, &data); err != nil {
		panic(err)
	}
	w.Write(buf.Bytes())
}
开发者ID:amrhassan,项目名称:rsc,代码行数:20,代码来源:play.go


示例6: oldRedirect

func oldRedirect(ctxt *fs.Context, w http.ResponseWriter, req *http.Request, p string) {
	m := map[string]string{}
	if key, ok := ctxt.CacheLoad("blog:oldRedirectMap", "blog/post", &m); !ok {
		dir, err := ctxt.ReadDir("blog/post")
		if err != nil {
			panic(err)
		}

		for _, d := range dir {
			meta, _, err := loadPost(ctxt, d.Name, req)
			if err != nil {
				// Should not happen: we just listed the directory.
				panic(err)
			}
			m[meta.OldURL] = "/" + d.Name
		}

		ctxt.CacheStore(key, m)
	}

	if url, ok := m[p]; ok {
		http.Redirect(w, req, url, http.StatusFound)
		return
	}

	notfound(ctxt, w, req)
}
开发者ID:amrhassan,项目名称:rsc,代码行数:27,代码来源:post.go


示例7: 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)
//.........这里部分代码省略.........
开发者ID:amrhassan,项目名称:rsc,代码行数:101,代码来源:dash.go



注:本文中的github.com/amrhassan/rsc/appfs/fs.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cc.Expr类代码示例发布时间:2022-05-24
下一篇:
Golang fs.RootFileSystem类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap