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

Golang hv.Package类代码示例

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

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



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

示例1: updateCacheInfo

func updateCacheInfo(remoteAddr string, pdoc *hv.Package, urpids, urpts *http.Cookie) (string, string) {
	pdoc.ViewedTime = time.Now().UTC().Unix()

	updateCachePros(remoteAddr, pdoc)
	updateProInfos(pdoc)
	return updateUrPros(pdoc, urpids, urpts)
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:7,代码来源:home.go


示例2: ConvertDataFormat

// ConvertDataFormat converts data from database acceptable format to useable format.
func ConvertDataFormat(pdoc *hv.Package, pdecl *models.PkgDecl) error {
	if pdoc.PkgDecl == nil {
		pdoc.PkgDecl = &hv.PkgDecl{}
	}

	pdoc.JsNum = pdecl.JsNum
	pdoc.IsHasExport = pdecl.IsHasExport
	pdoc.IsHasConst = pdecl.IsHasConst
	pdoc.IsHasVar = pdecl.IsHasVar
	pdoc.IsHasExample = pdecl.IsHasExample
	pdoc.IsHasFile = pdecl.IsHasFile
	pdoc.IsHasSubdir = pdecl.IsHasSubdir

	// Imports.
	pdoc.Imports = strings.Split(pdecl.Imports, "|")
	if len(pdoc.Imports) == 1 && len(pdoc.Imports[0]) == 0 {
		// No import.
		pdoc.Imports = nil
	}
	return nil
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:22,代码来源:home.go


示例3: generatePage

// generatePage genarates documentation page for project.
// it returns false when it's a invaild(empty) project.
func generatePage(this *HomeRouter, pdoc *hv.Package, q, tag string) bool {
	docPath := pdoc.ImportPath + utils.TagSuffix("-", tag)

	if pdoc.IsNeedRender {
		if !renderDoc(this, pdoc, q, tag, docPath) {
			return false
		}
	} else {
		pdecl, err := models.LoadProject(pdoc.Id, tag)
		if err != nil {
			beego.Error("HomeController.generatePage ->", err)
			return false
		}

		err = ConvertDataFormat(pdoc, pdecl)
		if err != nil {
			beego.Error("HomeController.generatePage -> ConvertDataFormat:", err)
			return false
		}

		this.Data["UtcTime"] = time.Unix(pdoc.Created, 0).UTC()
		this.Data["TimeSince"] = calTimeSince(time.Unix(pdoc.Created, 0))
	}

	// Add create time for JS files' link to prevent cache in case the page is recreated.
	this.Data["Timestamp"] = pdoc.Created

	proName := path.Base(pdoc.ImportPath)
	if i := strings.Index(proName, "?"); i > -1 {
		proName = proName[:i]
	}
	this.Data["ProName"] = proName

	// Check if need to show Hacker View.
	f := this.Input().Get("f")
	hvJs := utils.HvJsPath + pdoc.ImportPath + "/" + f + ".js"
	if len(tag) == 0 && (pdoc.IsCmd || pdoc.IsGoRepo || pdoc.IsGoSubrepo) &&
		len(f) > 0 && com.IsExist("."+hvJs) {
		this.TplNames = "hv.html"

		var query string
		if i := strings.Index(pdoc.ViewDirPath, "?"); i > -1 {
			query = pdoc.ViewDirPath[i:]
			pdoc.ViewDirPath = pdoc.ViewDirPath[:i]
		}
		this.Data["ViewDirPath"] = strings.TrimSuffix(pdoc.ViewDirPath, "/")
		this.Data["Query"] = query
		this.Data["FileName"] = f
		this.Data["HvJs"] = hvJs
		return true
	}

	// Set properties.
	this.TplNames = "docs.html"

	this.Data["PkgDesc"] = pdoc.Synopsis
	this.Data["Pid"] = pdoc.Id
	this.Data["IsGoRepo"] = pdoc.IsGoRepo

	if len(tag) == 0 && (pdoc.IsCmd || pdoc.IsGoRepo || pdoc.IsGoSubrepo) {
		this.Data["IsHasHv"] = true
	}

	// Refresh (within 10 seconds).
	this.Data["IsRefresh"] = time.Unix(pdoc.Created, 0).Add(10 * time.Second).After(time.Now())

	this.Data["VCS"] = pdoc.Vcs
	proPath := pdoc.ProjectPath

	// Introduction.
	this.Data["ImportPath"] = pdoc.ImportPath

	// README.
	lang := this.Data["Lang"].(string)[:2]
	readmePath := utils.DocsJsPath + docPath + "_RM_" + lang + ".js"
	if com.IsFile("." + readmePath) {
		this.Data["IsHasReadme"] = true
		this.Data["PkgDocPath"] = readmePath
	}

	// Index.
	this.Data["IsHasExports"] = pdoc.IsHasExport
	this.Data["IsHasConst"] = pdoc.IsHasConst
	this.Data["IsHasVar"] = pdoc.IsHasVar

	if !pdoc.IsCmd {
		this.Data["IsHasExams"] = pdoc.IsHasExample

		tags := strings.Split(pdoc.Tags, "|||")
		// Tags.
		if len(tag) == 0 {
			tag = tags[0]
		}
		this.Data["CurTag"] = tag
		this.Data["Tags"] = tags
		if strings.HasPrefix(proPath, "github.com") {
			offset := 6
			if len(tag) == 0 {
//.........这里部分代码省略.........
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:101,代码来源:home.go


示例4: renderDoc

func renderDoc(this *HomeRouter, pdoc *hv.Package, q, tag, docPath string) bool {
	this.Data["PkgFullIntro"] = pdoc.Doc

	var buf bytes.Buffer
	links := make([]*utils.Link, 0, len(pdoc.Types)+len(pdoc.Imports)+len(pdoc.TestImports)+
		len(pdoc.Funcs)+10)
	// Get all types, functions and import packages
	for _, t := range pdoc.Types {
		links = append(links, &utils.Link{
			Name:    t.Name,
			Comment: template.HTMLEscapeString(t.Doc),
		})
		buf.WriteString("'" + t.Name + "',")
	}

	for _, f := range pdoc.Funcs {
		links = append(links, &utils.Link{
			Name:    f.Name,
			Comment: template.HTMLEscapeString(f.Doc),
		})
		buf.WriteString("'" + f.Name + "',")
	}

	for _, t := range pdoc.Types {
		for _, f := range t.Funcs {
			links = append(links, &utils.Link{
				Name:    f.Name,
				Comment: template.HTMLEscapeString(f.Doc),
			})
			buf.WriteString("'" + f.Name + "',")
		}

		for _, m := range t.Methods {
			buf.WriteString("'" + t.Name + "_" + m.Name + "',")
		}
	}

	// Ignore C.
	for _, v := range append(pdoc.Imports, pdoc.TestImports...) {
		if v != "C" {
			links = append(links, &utils.Link{
				Name: path.Base(v) + ".",
				Path: v,
			})
		}
	}

	// Set exported objects type-ahead.
	exportDataSrc := buf.String()
	if len(exportDataSrc) > 0 {
		pdoc.IsHasExport = true
		this.Data["IsHasExports"] = true
		exportDataSrc = exportDataSrc[:len(exportDataSrc)-1]
		this.Data["ExportDataSrc"] = "<script>$('.search-export').typeahead({local: [" +
			exportDataSrc + "],limit: 10});</script>"
	}

	pdoc.UserExamples = getUserExamples(pdoc.ImportPath)

	pdoc.IsHasConst = len(pdoc.Consts) > 0
	pdoc.IsHasVar = len(pdoc.Vars) > 0
	if len(pdoc.Examples)+len(pdoc.UserExamples) > 0 {
		pdoc.IsHasExample = true
		this.Data["IsHasExample"] = pdoc.IsHasExample
		this.Data["Examples"] = append(pdoc.Examples, pdoc.UserExamples...)
	}

	// Commented and total objects number.
	var comNum, totalNum int

	// Constants.
	this.Data["IsHasConst"] = pdoc.IsHasConst
	this.Data["Consts"] = pdoc.Consts
	for i, v := range pdoc.Consts {
		if len(v.Doc) > 0 {
			buf.Reset()
			godoc.ToHTML(&buf, v.Doc, nil)
			v.Doc = buf.String()
		}
		buf.Reset()
		v.Decl = template.HTMLEscapeString(v.Decl)
		v.Decl = strings.Replace(v.Decl, "&#34;", "\"", -1)
		utils.FormatCode(&buf, &v.Decl, links)
		v.FmtDecl = buf.String()
		pdoc.Consts[i] = v
	}

	// Variables.
	this.Data["IsHasVar"] = pdoc.IsHasVar
	this.Data["Vars"] = pdoc.Vars
	for i, v := range pdoc.Vars {
		if len(v.Doc) > 0 {
			buf.Reset()
			godoc.ToHTML(&buf, v.Doc, nil)
			v.Doc = buf.String()
		}
		buf.Reset()
		utils.FormatCode(&buf, &v.Decl, links)
		v.FmtDecl = buf.String()
		pdoc.Vars[i] = v
//.........这里部分代码省略.........
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:101,代码来源:home.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang middleware.Context类代码示例发布时间:2022-05-28
下一篇:
Golang doc.Package类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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