本文整理汇总了Golang中github.com/Unknwon/gowalker/utils.IsGoRepoPath函数的典型用法代码示例。如果您正苦于以下问题:Golang IsGoRepoPath函数的具体用法?Golang IsGoRepoPath怎么用?Golang IsGoRepoPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsGoRepoPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteProject
// DeleteProject deletes everything about the path in database, and update import information.
func DeleteProject(path string) error {
// Check path length to reduce connect times. (except launchpad.net)
if path[0] != 'l' && len(strings.Split(path, "/")) <= 2 {
return errors.New("models.DeleteProject(): Short path as not needed.")
}
// Connect to database.
q := connDb()
defer q.Db.Close()
var i1, i2, i3 int64
// Delete package information.
info := new(PkgInfo)
err := q.WhereEqual("path", path).Find(info)
if err == nil {
i1, err = q.Delete(info)
if err != nil {
beego.Error("models.DeleteProject(): Information:", err)
}
}
// Delete package declaration
pdecl := new(PkgDecl)
err = q.WhereEqual("path", path).Find(pdecl)
if err == nil {
i2, err = q.Delete(pdecl)
if err != nil {
beego.Error("models.DeleteProject(): Declaration:", err)
} else if info.Id > 0 && !utils.IsGoRepoPath(path) {
// Don't need to check standard library.
// Update import information.
imports := strings.Split(pdecl.Imports, "|")
imports = imports[:len(imports)-1]
for _, v := range imports {
if !utils.IsGoRepoPath(v) {
// Only count non-standard library.
updateImportInfo(q, v, int(info.Id), false)
}
}
}
}
// Delete package documentation
pdoc := &PkgDoc{Path: path}
i3, err = q.Delete(pdoc)
if err != nil {
beego.Error("models.DeleteProject(): Documentation:", err)
}
if i1+i2+i3 > 0 {
beego.Info("models.DeleteProject(", path, i1, i2, i3, ")")
}
return nil
}
示例2: checkSpecialUsage
// checkSpecialUsage checks special usage of keywords.
// It returns true if it is a special usage, false otherwise.
func checkSpecialUsage(this *SearchRouter, q string) bool {
switch {
case q == "gorepo": // Show list of standard library.
pinfos, _ := models.GetGoRepo()
if len(pinfos) > 0 {
this.Data["IsFindPro"] = true
this.Data["Results"] = pinfos
}
return true
case q == "imports": // Show imports package list.
pkgs := strings.Split(this.Input().Get("pkgs"), "|")
pinfos, _ := models.GetGroupPkgInfo(pkgs)
if len(pinfos) > 0 {
this.Data["IsFindPro"] = true
this.Data["Results"] = pinfos
}
return true
case q == "imported": // Show packages that import this project.
pkgs := strings.Split(
strings.Replace(this.Input().Get("pkgs"), "$", "", -1), "|")
pinfos := models.GetGroupPkgInfoById(pkgs)
if len(pinfos) > 0 {
this.Data["IsFindPro"] = true
this.Data["Results"] = pinfos
}
return true
case strings.Index(q, ":l=") > -1: // Add label to the project.
// Get label(s).
i := strings.Index(q, ":l=")
if utils.IsGoRepoPath(q[:i]) {
this.Redirect("/"+q[:i], 302)
return true
}
if isLabel(q[i+3:]) && models.UpdateLabelInfo(q[:i], q[i+3:], true) {
this.Redirect("/"+q[:i], 302)
}
return true
case strings.Index(q, ":rl=") > -1: // Remove label to the project.
// Get label(s).
i := strings.Index(q, ":rl=")
if utils.IsGoRepoPath(q[:i]) {
this.Redirect("/"+q[:i], 302)
return true
}
if isLabel(q[i+4:]) && models.UpdateLabelInfo(q[:i], q[i+4:], false) {
this.Redirect("/"+q[:i], 302)
}
return true
}
return false
}
示例3: checkSpecialUsage
// checkSpecialUsage checks special usage of keywords.
// It returns true if it is a special usage, false otherwise.
func checkSpecialUsage(this *SearchController, q string) bool {
switch {
case q == "gorepo": // Show list of standard library.
pkgInfos, _ := models.GetGoRepo()
// Show results after searched.
if len(pkgInfos) > 0 {
this.Data["IsFindPro"] = true
this.Data["AllPros"] = pkgInfos
}
return true
case q == "imports": // Show imports package list.
pkgs := strings.Split(this.Input().Get("pkgs"), "|")
pinfos, _ := models.GetGroupPkgInfo(pkgs)
if len(pinfos) > 0 {
this.Data["IsFindPro"] = true
this.Data["AllPros"] = pinfos
}
return true
case q == "imported": // Show packages that import this project.
pkgs := strings.Split(this.Input().Get("pkgs"), "|")
pinfos, _ := models.GetGroupPkgInfoById(pkgs)
if len(pinfos) > 0 {
this.Data["IsFindPro"] = true
this.Data["AllPros"] = pinfos
}
return true
case strings.Index(q, ":tag=") > -1: // Add tag(s) to the project.
// Get tag(s).
i := strings.Index(q, ":tag=")
if utils.IsGoRepoPath(q[:i]) {
this.Redirect("/"+q[:i], 302)
return true
}
if isTag(q[i+5:]) && models.UpdateTagInfo(q[:i], q[i+5:], true) {
this.Redirect("/"+q[:i], 302)
}
return true
case strings.Index(q, ":rtag=") > -1: // Remove tag(s) to the project.
// Get tag(s).
i := strings.Index(q, ":rtag=")
if utils.IsGoRepoPath(q[:i]) {
this.Redirect("/"+q[:i], 302)
return true
}
if isTag(q[i+6:]) && models.UpdateTagInfo(q[:i], q[i+6:], false) {
this.Redirect("/"+q[:i], 302)
}
return true
}
return false
}
示例4: SaveProject
// SaveProject save package information, declaration, documentation to database, and update import information.
func SaveProject(pinfo *PkgInfo, pdecl *PkgDecl, pdoc *PkgDoc, imports []string) error {
// Connect to database.
q := connDb()
defer q.Close()
// Save package information.
info := new(PkgInfo)
err := q.WhereEqual("path", pinfo.Path).Find(info)
if err == nil {
pinfo.Id = info.Id
}
_, err = q.Save(pinfo)
if err != nil {
beego.Error("models.SaveProject -> Information:", err)
}
// Save package declaration
if pdecl != nil {
decl := new(PkgDecl)
cond := qbs.NewCondition("path = ?", pinfo.Path).And("tag = ?", pdecl.Tag)
err = q.Condition(cond).Find(decl)
if err == nil {
pdecl.Id = decl.Id
}
_, err = q.Save(pdecl)
if err != nil {
beego.Error("models.SaveProject -> Declaration:", err)
}
}
// Save package documentation
if pdoc != nil && len(pdoc.Doc) > 0 {
_, err = q.Save(pdoc)
if err != nil {
beego.Error("models.SaveProject -> Documentation:", err)
}
}
// Don't need to check standard library.
if imports != nil && !utils.IsGoRepoPath(pinfo.Path) {
// Update import information.
for _, v := range imports {
if !utils.IsGoRepoPath(v) {
// Only count non-standard library.
updateImportInfo(q, v, int(pinfo.Id), true)
}
}
}
return nil
}
示例5: getRepo
// getRepo downloads package data.
func getRepo(client *http.Client, importPath string, etag string) (pdoc *Package, err error) {
const VER_PREFIX = PACKAGE_VER + "-"
// Check version prefix.
if strings.HasPrefix(etag, VER_PREFIX) {
etag = etag[len(VER_PREFIX):]
} else {
etag = ""
}
switch {
case utils.IsGoRepoPath(importPath):
pdoc, err = getStandardDoc(client, importPath, etag)
case utils.IsValidRemotePath(importPath):
pdoc, err = getStatic(client, importPath)
if err == errNoMatch {
pdoc, err = getDynamic(client, importPath)
}
default:
return nil, errors.New("doc.getRepo(): No match: " + importPath)
}
// Save revision tag.
if pdoc != nil {
pdoc.Etag = VER_PREFIX + pdoc.Etag
}
return pdoc, err
}
示例6: getRepo
// getRepo downloads package data and returns 'Package' by given import path and tag.
// It returns error when error occurs in the underlying functions.
func getRepo(client *http.Client, path, tag, ptag string) (pdoc *hv.Package, err error) {
switch {
case utils.IsGoRepoPath(path):
pdoc, err = getStandardDoc(client, path, tag, ptag)
case utils.IsValidRemotePath(path):
pdoc, err = getStatic(client, path, tag, ptag)
if err == errNoMatch {
pdoc, err = getDynamic(client, path, tag, ptag)
}
default:
return nil, errors.New(
fmt.Sprintf("doc.getRepo -> No match( %s:%s )", path, tag))
}
if pdoc == nil {
return nil, err
}
pdoc.PkgVer = hv.PACKAGE_VER
// Render README.
for name, content := range pdoc.Readme {
p, err := httplib.Post("https://api.github.com/markdown/raw?"+GetGithubCredentials()).
Header("Content-Type", "text/plain").Body(content).Bytes()
if err != nil {
return nil, errors.New(
fmt.Sprintf("doc.getRepo -> Render README( %s:%s ): %v", path, tag, err))
}
pdoc.Readme[name] = p
}
return pdoc, err
}
示例7: crawlDoc
// crawlDoc fetchs package from VCS.
func crawlDoc(path string, etag string, views int64) (pdoc *Package, err error) {
// I have no idea what the fuck does this mean.
if i := strings.Index(path, "/libgo/go/"); i > 0 && utils.IsGoRepoPath(path[i+len("/libgo/go/"):]) {
// Go Frontend source tree mirror.
pdoc = nil
err = errors.New("Go Frontend source tree mirror.")
} else {
var pdocNew *Package
pdocNew, err = getRepo(httpClient, path, etag)
// For timeout logic in client.go to work, we cannot leave connections idling. This is ugly.
httpTransport.CloseIdleConnections()
if err != errNotModified && pdocNew != nil {
pdoc = pdocNew
pdoc.Views = views
}
}
switch {
case err == nil:
pdoc.Views = views
if err = SaveProject(pdoc); err != nil {
beego.Error("doc.SaveProject(", path, "):", err)
}
case isNotFound(err):
// We do not need to delete standard library, so here is fine.
if err = models.DeleteProject(path); err != nil {
beego.Error("doc.DeleteProject(", path, "):", err)
}
}
return pdoc, err
}
示例8: getPkgInfoWithQ
func getPkgInfoWithQ(path, tag string, q *qbs.Qbs) (*hv.PkgInfo, error) {
// Check path length to reduce connect times.
if len(path) == 0 {
return nil, errors.New("models.getPkgInfoWithQ -> Empty path as not found.")
}
pinfo := new(hv.PkgInfo)
q.WhereEqual("import_path", path).Find(pinfo)
proPath := utils.GetProjectPath(path)
if utils.IsGoRepoPath(path) {
proPath = "code.google.com/p/go"
}
beego.Trace("models.getPkgInfoWithQ -> proPath:", proPath)
ptag := new(PkgTag)
cond := qbs.NewCondition("path = ?", proPath).And("tag = ?", tag)
err := q.Condition(cond).Find(ptag)
if err != nil {
pinfo.Ptag = "ptag"
return pinfo, errors.New(
fmt.Sprintf("models.getPkgInfoWithQ( %s:%s ) -> 'PkgTag': %s", path, tag, err))
}
pinfo.Vcs = ptag.Vcs
pinfo.Tags = ptag.Tags
// Only 'PkgInfo' cannot prove that package exists,
// we have to check 'PkgDecl' as well in case it was deleted by mistake.
pdecl := new(PkgDecl)
cond = qbs.NewCondition("pid = ?", pinfo.Id).And("tag = ?", tag)
err = q.Condition(cond).Find(pdecl)
if err != nil {
// Basically, error means not found, so we set 'pinfo.PkgVer' to 0
// because server uses it to decide whether force update.
pinfo.PkgVer = 0
pinfo.Ptag = "ptag"
return pinfo, errors.New(
fmt.Sprintf("models.getPkgInfoWithQ( %s:%s ) -> 'PkgDecl': %s", path, tag, err))
}
docPath := path + utils.TagSuffix("-", tag)
if !com.IsExist("." + utils.DocsJsPath + docPath + ".js") {
pinfo.PkgVer = 0
pinfo.Ptag = "ptag"
return pinfo, errors.New(
fmt.Sprintf("models.getPkgInfoWithQ( %s:%s ) -> JS: File not found", path, tag))
}
return pinfo, nil
}
示例9: SaveProject
// SaveProject save package information, declaration, documentation to database, and update import information.
func SaveProject(pinfo *PkgInfo, pdecl *PkgDecl, pdoc *PkgDoc, imports []string) error {
// Connect to database.
q, err := connDb()
if err != nil {
beego.Error("models.SaveProject():", err)
}
defer q.Db.Close()
// Save package information.
info := new(PkgInfo)
err = q.WhereEqual("path", pinfo.Path).Find(info)
if err != nil {
_, err = q.Save(pinfo)
} else {
pinfo.Id = info.Id
_, err = q.Save(pinfo)
}
if err != nil {
beego.Error("models.SaveProject(): Information:", err)
}
// Save package declaration
_, err = q.Save(pdecl)
if err != nil {
beego.Error("models.SaveProject(): Declaration:", err)
}
// Save package documentation
if len(pdoc.Doc) > 0 {
_, err = q.Save(pdoc)
if err != nil {
beego.Error("models.SaveProject(): Documentation:", err)
}
}
// Update import information.
for _, v := range imports {
if !utils.IsGoRepoPath(v) {
// Only count non-standard library.
updateImportInfo(q, v, int(pinfo.Id), true)
}
}
return nil
}
示例10: getRepo
// getRepo downloads package data and returns 'Package' by given import path and tag.
// It returns error when error occurs in the underlying functions.
func getRepo(client *http.Client, path, tag, ptag string) (pdoc *hv.Package, err error) {
switch {
case utils.IsGoRepoPath(path):
pdoc, err = getStandardDoc(client, path, tag, ptag)
case utils.IsValidRemotePath(path):
pdoc, err = getStatic(client, path, tag, ptag)
if err == errNoMatch {
pdoc, err = getDynamic(client, path, tag, ptag)
}
default:
return nil, errors.New(
fmt.Sprintf("doc.getRepo -> No match( %s:%s )", path, tag))
}
if pdoc != nil {
pdoc.PkgVer = hv.PACKAGE_VER
}
return pdoc, err
}
示例11: Get
// Get implemented Get method for HomeRouter.
func (this *HomeRouter) Get() {
// Filter unusual User-Agent.
ua := this.Ctx.Request.Header.Get("User-Agent")
if len(ua) < 20 {
beego.Warn("User-Agent:", this.Ctx.Request.Header.Get("User-Agent"))
this.Ctx.WriteString("")
return
}
// Set language version.
curLang := globalSetting(this.Ctx, this.Input(), this.Data)
// Get argument(s).
q := strings.TrimRight(
strings.TrimSpace(this.Input().Get("q")), "/")
if path, ok := utils.IsBrowseURL(q); ok {
q = path
}
// Get pure URL.
reqUrl := this.Ctx.Request.RequestURI[1:]
if i := strings.Index(reqUrl, "?"); i > -1 {
reqUrl = reqUrl[:i]
if path, ok := utils.IsBrowseURL(reqUrl); ok {
reqUrl = path
}
}
// Redirect to query string.
if len(reqUrl) == 0 && len(q) > 0 {
reqUrl = q
this.Redirect("/"+reqUrl, 302)
return
}
// User Recent projects.
urpids, _ := this.Ctx.Request.Cookie("UserRecentPros")
urpts, _ := this.Ctx.Request.Cookie("URPTimestamps")
this.TplNames = "home_" + curLang.Lang + ".html"
// Check to show home page or documentation page.
if len(reqUrl) == 0 && len(q) == 0 {
serveHome(this, urpids, urpts)
} else {
// Documentation.
this.TplNames = "docs_" + curLang.Lang + ".html"
broPath := reqUrl // Browse path.
// Check if it's the standard library.
if utils.IsGoRepoPath(broPath) {
broPath = "code.google.com/p/go/source/browse/src/pkg/" + broPath
}
// Check if it's a remote path that can be used for 'go get', if not means it's a keyword.
if !utils.IsValidRemotePath(broPath) {
// Search.
this.Redirect("/search?q="+reqUrl, 302)
return
}
// Get tag field.
tag := strings.TrimSpace(this.Input().Get("tag"))
if tag == "master" || tag == "default" {
tag = ""
}
// Check documentation of this import path, and update automatically as needed.
pdoc, err := doc.CheckDoc(reqUrl, tag, doc.HUMAN_REQUEST)
if err == nil {
if pdoc != nil {
pdoc.UserExamples = getUserExamples(pdoc.ImportPath)
// Generate documentation page.
if generatePage(this, pdoc, broPath, tag, curLang.Lang) {
ps, ts := updateCacheInfo(pdoc, urpids, urpts)
this.Ctx.SetCookie("UserRecentPros", ps, 9999999999, "/")
this.Ctx.SetCookie("URPTimestamps", ts, 9999999999, "/")
return
}
}
} else {
this.Data["IsHasError"] = true
this.Data["ErrMsg"] = strings.Replace(err.Error(),
doc.GetGithubCredentials(), "<githubCred>", 1)
beego.Error("HomeRouter.Get ->", err)
this.TplNames = "home_" + curLang.Lang + ".html"
serveHome(this, urpids, urpts)
return
}
this.Redirect("/search?q="+reqUrl, 302)
return
}
}
示例12: generatePage
// generatePage genarates documentation page for project.
// it returns false when its a invaild(empty) project.
func generatePage(this *HomeController, pdoc *doc.Package, q string, lang string) bool {
// Set properties.
this.TplNames = "docs_" + lang + ".html"
// Refresh (within 10 seconds).
this.Data["IsRefresh"] = pdoc.Created.Add(10 * time.Second).UTC().After(time.Now().UTC())
// Get project name.
lastIndex := strings.LastIndex(q, "/")
proName := q[lastIndex+1:]
if i := strings.Index(proName, "?"); i > -1 {
proName = proName[:i]
}
this.Data["ProName"] = proName
// Project VCS home page.
switch {
case q[:4] == "code": // code.google.com
if strings.Index(q, "source/") == -1 {
this.Data["ProPath"] = strings.Replace(q, pdoc.ProjectName, pdoc.ProjectName+"/source/browse", 1)
} else {
this.Data["ProPath"] = q
}
case q[:3] == "git": // github.com
if proName != pdoc.ProjectName {
// Not root.
this.Data["ProPath"] = strings.Replace(q, proName, "tree/master/"+proName, 1)
} else {
this.Data["ProPath"] = q + "/tree/master"
}
}
this.Data["Views"] = pdoc.Views + 1
// Remove last "/".
if urlLen := len(q); q[urlLen-1] == '/' {
q = q[:urlLen-1]
}
if utils.IsGoRepoPath(pdoc.ImportPath) {
this.Data["IsGoRepo"] = true
}
pkgDocPath := q[:lastIndex]
this.Data["ProDocPath"] = pkgDocPath // Upper level project URL.
// Introduction.
this.Data["ImportPath"] = pdoc.ImportPath
// Load project data from database.
pdecl, err := models.LoadProject(pdoc.ImportPath)
if err != nil {
beego.Error("SearchController.generatePage(): models.LoadProject()", err)
return false
}
var buf bytes.Buffer
godoc.ToHTML(&buf, pdecl.Doc, nil)
pkgInfo := buf.String()
pkgInfo = strings.Replace(pkgInfo, "<p>", "<p><b>", 1)
pkgInfo = strings.Replace(pkgInfo, "</p>", "</b></p>", 1)
this.Data["PkgFullIntro"] = pkgInfo
// Convert data format.
err = ConvertDataFormat(pdoc, pdecl)
if err != nil {
beego.Error("SearchController.generatePage(): ConvertDataFormat", err)
return false
}
links := make([]*utils.Link, 0, len(pdoc.Types)+len(pdoc.Imports))
// Get all types and import packages
for _, t := range pdoc.Types {
links = append(links, &utils.Link{
Name: t.Name,
Comment: t.Doc,
})
}
for _, v := range pdoc.Imports {
links = append(links, &utils.Link{
Name: path.Base(v) + ".",
Path: v,
})
}
// Index.
this.Data["IsHasConst"] = len(pdoc.Consts) > 0
this.Data["IsHasVar"] = len(pdoc.Vars) > 0
this.Data["Funcs"] = pdoc.Funcs
for i, f := range pdoc.Funcs {
buf.Reset()
godoc.ToHTML(&buf, f.Doc, nil)
f.Doc = buf.String()
buf.Reset()
utils.FormatCode(&buf, f.Decl, links)
f.FmtDecl = buf.String()
buf.Reset()
utils.FormatCode(&buf, f.Code, links)
f.Code = buf.String()
pdoc.Funcs[i] = f
}
this.Data["Types"] = pdoc.Types
//.........这里部分代码省略.........
示例13: Get
// Get implemented Get method for HomeController.
// It serves home page of Go Walker.
func (this *HomeController) Get() {
// Print unusual User-Agent.
ua := this.Ctx.Request.Header.Get("User-Agent")
if len(ua) < 20 {
beego.Trace("User-Agent:", this.Ctx.Request.Header.Get("User-Agent"))
}
// Check language version by different ways.
lang := checkLangVer(this.Ctx.Request, this.Input().Get("lang"))
// Get language version.
curLang, restLangs := getLangVer(
this.Ctx.Request.Header.Get("Accept-Language"), lang)
// Save language information in cookies.
this.Ctx.SetCookie("lang", curLang.Lang+";path=/", 0)
// Get query field.
q := strings.TrimSpace(this.Input().Get("q"))
if path, ok := utils.IsBrowseURL(q); ok {
q = path
}
// Get pure URL.
reqUrl := this.Ctx.Request.RequestURI[1:]
if i := strings.Index(reqUrl, "?"); i > -1 {
reqUrl = reqUrl[:i]
}
if len(reqUrl) == 0 && len(q) > 0 {
reqUrl = q
}
// Set properties
this.Layout = "layout_" + curLang.Lang + ".html"
// Set language properties.
this.Data["Lang"] = curLang.Lang
this.Data["CurLang"] = curLang.Name
this.Data["RestLangs"] = restLangs
// Check show home page or documentation page.
if len(reqUrl) == 0 && len(q) == 0 {
// Home page.
this.TplNames = "home_" + curLang.Lang + ".html"
// Recent projects
this.Data["RecentPros"] = recentViewedPros
// Get popular project list from database.
pkgInfos, _ := models.GetPopularPros()
this.Data["PopPros"] = pkgInfos
// Set standard library keyword type-ahead.
this.Data["DataSrc"] = utils.GoRepoSet
} else {
// Documentation page.
broPath := reqUrl // Browse path.
// Check if it is standard library.
if utils.IsGoRepoPath(broPath) {
broPath = "code.google.com/p/go/source/browse/src/pkg/" + broPath
}
// Check if it is a remote path that can be used for 'go get', if not means it's a keyword.
if !utils.IsValidRemotePath(broPath) {
// Show search page
this.Redirect("/search?q="+reqUrl, 302)
return
}
// Check documentation of this import path, and update automatically as needed.
pdoc, err := doc.CheckDoc(reqUrl, doc.HUMAN_REQUEST)
if err == nil {
// Generate documentation page.
/* TODO */
if pdoc != nil && generatePage(this, pdoc, broPath, curLang.Lang) {
// Update recent project list.
updateRecentPros(pdoc)
// Update project views.
pinfo := &models.PkgInfo{
Path: pdoc.ImportPath,
Synopsis: pdoc.Synopsis,
Created: pdoc.Created,
ProName: pdoc.ProjectName,
ViewedTime: pdoc.ViewedTime,
Views: pdoc.Views,
Etag: pdoc.Etag,
}
models.AddViews(pinfo)
return
}
} else {
beego.Error("HomeController.Get():", err)
}
// Show search page
//.........这里部分代码省略.........
示例14: generatePage
// generatePage genarates documentation page for project.
// it returns false when its a invaild(empty) project.
func generatePage(this *HomeController, pdoc *doc.Package, q string, lang string) bool {
// Load project data from database.
pdecl, err := models.LoadProject(pdoc.ImportPath)
if err != nil {
beego.Error("HomeController.generatePage():", err)
return false
}
// Set properties.
this.TplNames = "docs_" + lang + ".html"
// Refresh (within 10 seconds).
this.Data["IsRefresh"] = pdoc.Created.Add(10 * time.Second).UTC().After(time.Now().UTC())
// Get VCS name, project name, project home page, and Upper level project URL.
this.Data["VCS"], this.Data["ProName"], this.Data["ProPath"], this.Data["ProDocPath"] = getVCSInfo(q, pdoc)
if utils.IsGoRepoPath(pdoc.ImportPath) &&
strings.Index(pdoc.ImportPath, ".") == -1 {
this.Data["IsGoRepo"] = true
}
this.Data["Views"] = pdoc.Views + 1
// Tags.
this.Data["Tags"] = getTags(pdoc.Tags, lang)
// Introduction.
this.Data["ImportPath"] = pdoc.ImportPath
byts, _ := base32.StdEncoding.DecodeString(pdecl.Doc)
this.Data["PkgFullIntro"] = string(byts)
var buf bytes.Buffer
// Convert data format.
err = ConvertDataFormat(pdoc, pdecl)
if err != nil {
beego.Error("HomeController.generatePage(): ConvertDataFormat", err)
return false
}
links := make([]*utils.Link, 0, len(pdoc.Types)+len(pdoc.Imports)+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 + "",")
}
}
for _, v := range pdoc.Imports {
links = append(links, &utils.Link{
Name: path.Base(v) + ".",
Path: v,
})
}
exportDataSrc := buf.String()
if len(exportDataSrc) > 0 {
this.Data["HasExports"] = true
exportDataSrc = exportDataSrc[:len(exportDataSrc)-1]
// Set export keyword type-ahead.
this.Data["ExportDataSrc"] = exportDataSrc
}
// Index.
this.Data["IsHasConst"] = len(pdoc.Consts) > 0
this.Data["IsHasVar"] = len(pdoc.Vars) > 0
this.Data["Funcs"] = pdoc.Funcs
for i, f := range pdoc.Funcs {
buf.Reset()
godoc.ToHTML(&buf, f.Doc, nil)
f.Doc = buf.String()
buf.Reset()
utils.FormatCode(&buf, &f.Decl, links)
f.FmtDecl = buf.String()
//.........这里部分代码省略.........
示例15: Get
// Get implemented Get method for HomeRouter.
func (this *HomeRouter) Get() {
// Get argument(s).
q := strings.TrimRight(
strings.TrimSpace(this.Input().Get("q")), "/")
if path, ok := utils.IsBrowseURL(q); ok {
q = path
}
// Get pure URL.
reqUrl := this.Ctx.Request.RequestURI[1:]
if i := strings.Index(reqUrl, "?"); i > -1 {
reqUrl = reqUrl[:i]
if path, ok := utils.IsBrowseURL(reqUrl); ok {
reqUrl = path
}
}
// Redirect to query string.
if len(reqUrl) == 0 && len(q) > 0 {
reqUrl = q
this.Redirect("/"+reqUrl, 302)
return
}
// User History.
urpids, _ := this.Ctx.Request.Cookie("UserHistory")
urpts, _ := this.Ctx.Request.Cookie("UHTimestamps")
if len(reqUrl) == 0 && len(q) == 0 {
serveHome(this, urpids, urpts)
return
}
// Documentation page.
broPath := reqUrl // Browse path.
// Check if it's the standard library.
if utils.IsGoRepoPath(broPath) {
broPath = "code.google.com/p/go/source/browse/src/pkg/" + broPath
} else if utils.IsGoSubrepoPath(broPath) {
this.Redirect("/code.google.com/p/"+broPath, 301)
return
} else if strings.Index(broPath, "source/browse/") > -1 {
broPath = strings.Replace(broPath, "source/browse/", "", 1)
}
// Check if it's a remote path that can be used for 'go get', if not means it's a keyword.
if !utils.IsValidRemotePath(broPath) {
// Search.
this.Redirect("/search?q="+reqUrl, 302)
return
}
// Get tag field.
tag := strings.TrimSpace(this.Input().Get("tag"))
if tag == "master" || tag == "default" {
tag = ""
}
// Check documentation of current import path, update automatically as needed.
pdoc, err := doc.CheckDoc(reqUrl, tag, doc.RT_Human)
if err == nil {
// errNoMatch leads to pdoc == nil.
if pdoc != nil {
// Generate documentation page.
if generatePage(this, pdoc, broPath, tag) {
ps, ts := updateCacheInfo(pdoc, urpids, urpts)
this.Ctx.SetCookie("UserHistory", ps, 9999999999, "/")
this.Ctx.SetCookie("UHTimestamps", ts, 9999999999, "/")
return
}
}
this.Redirect("/search?q="+reqUrl, 302)
return
}
// Error.
this.Data["IsHasError"] = true
this.Data["ErrMsg"] = strings.Replace(err.Error(),
doc.GetGithubCredentials(), "<githubCred>", 1)
if !strings.Contains(err.Error(), "Cannot find Go files") {
beego.Error("HomeRouter.Get ->", err)
}
serveHome(this, urpids, urpts)
}