示例#1
0
func handleProfile(ctx *macaron.Context) string {
	switch ctx.Query("op") {
	case "startcpu":
		if err := StartCPUProfile(); err != nil {
			return err.Error()
		}
	case "stopcpu":
		if err := StopCPUProfile(); err != nil {
			return err.Error()
		}
	case "mem":
		dumpMemProf()
	case "gc":
		var buf bytes.Buffer
		DumpGCSummary(&buf)
		return string(buf.Bytes())
	default:
		return fmt.Sprintf(`<p>Available operations:</p>
<ol>
	<li><a href="%s?op=startcpu">Start CPU profile</a></li>
	<li><a href="%s?op=stopcpu">Stop CPU profile</a></li>
	<li><a href="%s?op=mem">Dump memory profile</a></li>
	<li><a href="%s?op=gc">Dump GC summary</a></li>
</ol>`, opt.ProfileURLPrefix, opt.ProfileURLPrefix, opt.ProfileURLPrefix, opt.ProfileURLPrefix)
	}
	ctx.Redirect(opt.ProfileURLPrefix)
	return ""
}
示例#2
0
文件: gogs.go 项目: zzhua/gogsweb
func docs(ctx *macaron.Context, locale i18n.Locale, name string) {
	docRoot := models.GetDocByLocale(name, locale.Lang)
	if docRoot == nil {
		docRoot = models.GetDocByLocale(name, "en-US")
	}

	link := strings.TrimPrefix(ctx.Params("*"), "/")
	link = strings.TrimSuffix(link, ".html")
	link = strings.TrimSuffix(link, ".md")
	ctx.Data["Link"] = "/docs/" + link

	var doc *models.DocNode
	if len(link) == 0 {
		ctx.Redirect("/docs/intro/")
		return
	}

	doc, _ = docRoot.GetNodeByLink(link)
	if doc == nil {
		doc, _ = docRoot.GetNodeByLink(link + "/")
	}
	if doc == nil {
		ctx.Error(404)
		return
	}

	ctx.Data["DocRoot"] = docRoot
	ctx.Data["Doc"] = doc
	ctx.Data["Title"] = doc.Name
	ctx.Data["Data"] = doc.GetContent()
	ctx.HTML(200, "document_"+name, ctx.Data)
}
示例#3
0
func login(ctx *macaron.Context, s session.Store, opt *Options) {
	next := extractPath(ctx.Query(KEY_NEXT_PAGE))
	if s.Get(KEY_TOKEN) == nil {
		// User is not logged in.
		if next == "" {
			next = AppSubUrl + "/"
		}
		// println(111, opt.AuthCodeURL(next, "", ""))
		ctx.Redirect(opt.AuthCodeURL(next, "", ""))
		return
	}
	// No need to login, redirect to the next page.
	ctx.Redirect(next)
}
示例#4
0
func handleOAuth2Callback(ctx *macaron.Context, s session.Store, opt *Options) {
	next := extractPath(ctx.Query("state"))
	code := ctx.Query("code")
	t, err := opt.NewTransportFromCode(code)
	if err != nil {
		// Pass the error message, or allow dev to provide its own
		// error handler.
		println(err.Error())
		ctx.Redirect(PathError)
		return
	}
	// Store the credentials in the session.
	val, _ := json.Marshal(t.Token())
	s.Set(KEY_TOKEN, val)
	ctx.Redirect(next)
}
示例#5
0
func Docs(ctx *macaron.Context, locale i18n.Locale) {
	docRoot := models.GetDocByLocale(
		"gitea",
		locale.Lang)

	if docRoot == nil {
		ctx.Error(404)
		return
	}

	link := strings.TrimSuffix(
		strings.TrimSuffix(
			strings.TrimPrefix(
				ctx.Params("*"),
				"/"),
			".html"),
		".md")

	ctx.Data["Link"] = "/docs/" + link

	if len(link) == 0 {
		ctx.Redirect("/docs/intro/")
		return
	}

	doc, _ := docRoot.GetNodeByLink(link)

	if doc == nil {
		doc, _ = docRoot.GetNodeByLink(link + "/")
	}

	if doc == nil {
		ctx.Error(404)
		return
	}

	ctx.Data["DocRoot"] = docRoot
	ctx.Data["Doc"] = doc
	ctx.Data["Title"] = doc.Name
	ctx.Data["Data"] = doc.GetContent()
	ctx.HTML(200, "gitea", ctx.Data)
}
示例#6
0
func logout(ctx *macaron.Context, s session.Store) {
	next := extractPath(ctx.Query(KEY_NEXT_PAGE))
	s.Delete(KEY_TOKEN)
	ctx.Redirect(next)
}