Exemple #1
0
// Get implemented Get method for RefreshRouter.
func (this *RefreshRouter) Get() {
	this.TplNames = "refresh.html"

	// Get argument(s).
	q := this.Input().Get("q")

	// Empty query string shows home page.
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	pdoc, err := doc.CheckDoc(q, "", doc.RT_Refresh)
	if err == nil && pdoc != nil {
		os.Remove("." + utils.DocsJsPath + pdoc.ImportPath + ".js")
		this.Redirect("/"+q, 302)
		return
	}

	if strings.HasPrefix(err.Error(), "doc.") || strings.HasSuffix(err.Error(), "EOF") {
		this.Data["IsHasError"] = true
		this.Data["ErrMsg"] = strings.Replace(err.Error(),
			doc.GetGithubCredentials(), "<githubCred>", 1)
		return
	}

	if strings.Contains(err.Error(), "Package not modified") {
		this.Redirect("/"+q, 302)
		return
	}

	this.Data["Path"] = q
	this.Data["LimitTime"] = err.Error()
}
Exemple #2
0
// Get implemented Get method for RefreshController.
// It serves refresh page of Go Walker.
func (this *RefreshController) Get() {
	// Set language version.
	curLang, restLangs := setLangVer(this.Ctx.Request, this.Input())

	// Save language information in cookies.
	this.Ctx.SetCookie("lang", curLang.Lang+";path=/", 0)

	// Get query field
	q := this.Input().Get("q")

	// Empty query string shows home page
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	// Set properties
	this.Layout = "layout_" + curLang.Lang + ".html"
	this.TplNames = "refresh_" + curLang.Lang + ".html"

	// Set language properties.
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs

	pdoc, err := doc.CheckDoc(q, doc.REFRESH_REQUEST)
	if err == nil {
		pinfo := &models.PkgInfo{
			Path:        pdoc.ImportPath,
			Synopsis:    pdoc.Synopsis,
			Created:     pdoc.Created,
			ProName:     pdoc.ProjectName,
			ViewedTime:  pdoc.ViewedTime,
			Views:       pdoc.Views,
			Etag:        pdoc.Etag,
			Tags:        pdoc.Tags,
			ImportedNum: pdoc.ImportedNum,
			ImportPid:   pdoc.ImportPid,
		}
		models.SaveProject(pinfo, nil, nil, nil)
		// Show search page
		this.Redirect("/"+q, 302)
		return
	}

	// Set data
	this.Data["Path"] = q
	this.Data["LimitTime"] = err.Error()
}
Exemple #3
0
func (this *ApiRouter) Refresh() {
	var result struct {
		Ok        bool   `json:"ok"`
		LimitTime string `json:"limit_time"`
	}
	_, err := doc.CheckDoc(this.GetString("pkgname"), "", doc.RT_Refresh)
	if err == nil {
		result.Ok = true
	} else {
		result.Ok = false
		result.LimitTime = err.Error()
	}
	this.Data["json"] = &result
	this.ServeJson(true)
}
Exemple #4
0
// Get implemented Get method for RefreshRouter.
func (this *RefreshRouter) Get() {
	// Set language version.
	curLang := globalSetting(this.Ctx, this.Input(), this.Data)

	// Get argument(s).
	q := this.Input().Get("q")

	// Empty query string shows home page.
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	// Set properties.
	this.TplNames = "refresh_" + curLang.Lang + ".html"

	pdoc, err := doc.CheckDoc(q, "", doc.REFRESH_REQUEST)
	if err == nil {
		pinfo := &models.PkgInfo{
			Path:        pdoc.ImportPath,
			ProName:     pdoc.ProjectName,
			Synopsis:    pdoc.Synopsis,
			IsCmd:       pdoc.IsCmd,
			Tags:        strings.Join(pdoc.Tags, "|||"),
			Views:       pdoc.Views,
			ViewedTime:  pdoc.ViewedTime,
			Created:     pdoc.Created,
			Rank:        pdoc.Rank,
			Etag:        pdoc.Etag,
			Labels:      pdoc.Labels,
			ImportedNum: pdoc.ImportedNum,
			ImportPid:   pdoc.ImportPid,
			Note:        pdoc.Note,
		}
		models.SaveProject(pinfo, nil, nil, nil)

		this.Redirect("/"+q, 302)
		return
	}

	this.Data["Path"] = q
	this.Data["LimitTime"] = err.Error()
}
Exemple #5
0
// Get implemented Get method for RefreshController.
// It serves refresh page of Go Walker.
func (this *RefreshController) Get() {
	// 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 := this.Input().Get("q")

	// Empty query string shows home page
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	// Set properties
	this.Layout = "layout_" + curLang.Lang + ".html"
	this.TplNames = "refresh_" + curLang.Lang + ".html"

	// Set language properties.
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs

	_, err := doc.CheckDoc(q, doc.REFRESH_REQUEST)
	if err == nil {
		// Show search page
		this.Redirect("/"+q, 302)
		return
	}

	// Set data
	this.Data["Path"] = q
	this.Data["LimitTime"] = err.Error()
}
Exemple #6
0
// 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
		this.Redirect("/search?q="+reqUrl, 302)
		return
	}
}
Exemple #7
0
// 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)
}
Exemple #8
0
// 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"))
		return
	}

	// Set language version.
	curLang := setLangVer(this.Ctx, this.Input(), this.Data)

	// Get query field.
	q := strings.TrimSpace(this.Input().Get("q"))

	// Remove last "/".
	q = strings.TrimRight(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
	}

	// Check show home page or documentation page.
	if len(reqUrl) == 0 && len(q) == 0 {
		// Home page.
		this.Data["IsHome"] = true
		this.TplNames = "home_" + curLang.Lang + ".html"

		// Recent projects
		this.Data["RecentPros"] = recentViewedPros
		// Get popular project and examples list from database.
		this.Data["PopPros"], this.Data["RecentExams"] = models.GetPopulars(20, 12)
		// Set standard library keyword type-ahead.
		this.Data["DataSrc"] = utils.GoRepoSet
	} else {
		// Documentation page.
		this.TplNames = "docs_" + curLang.Lang + ".html"
		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 'gopm get', if not means it's a keyword.
		if !utils.IsValidRemotePath(broPath) {
			// Show search page
			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 || pdoc == nil {
			pdoc.UserExamples = getUserExamples(pdoc.ImportPath)
			// Generate documentation page.
			if generatePage(this, pdoc, broPath, tag, 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,
					IsCmd:       pdoc.IsCmd,
					Etag:        pdoc.Etag,
					Labels:      pdoc.Labels,
					Tags:        strings.Join(pdoc.Tags, "|||"),
					ImportedNum: pdoc.ImportedNum,
					ImportPid:   pdoc.ImportPid,
				}
				models.AddViews(pinfo)
				return
			}
		} else {
			beego.Error("HomeRouter.Get ->", err)
		}

		// Show search page
		this.Redirect("/search?q="+reqUrl, 302)
		return
	}
}
Exemple #9
0
// 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
	}
}