本文整理汇总了Golang中github.com/Unknwon/macaron.Context.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Error方法的具体用法?Golang Context.Error怎么用?Golang Context.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Unknwon/macaron.Context
的用法示例。
在下文中一共展示了Context.Error方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: docs
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)
}
示例2: Static
func Static(ctx *macaron.Context) {
if len(ctx.Params(":all")) > 0 {
f, err := os.Open(
path.Join(
"docs",
"gitea",
"images",
ctx.Params(":all")))
defer f.Close()
if err != nil {
ctx.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
}
if _, err = io.Copy(ctx.RW(), f); err != nil {
ctx.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
}
return
}
ctx.Error(404)
}
示例3: RecentBuild
func RecentBuild(ctx *macaron.Context) {
var repos []models.Repository
err := models.DB.Limit(10).Desc("trigger_at").Where("valid=?", true).Find(&repos)
if err != nil {
ctx.Error(500, err.Error())
return
}
ctx.JSON(200, repos)
}
示例4: RepoList
func RepoList(ctx *macaron.Context) {
var repos []models.Repository
// TODO: change limit to paginate
err := models.DB.Limit(100).Where("valid=?", true).Desc("updated_at").Find(&repos)
if err != nil {
ctx.Error(500, err.Error())
return
}
ctx.JSON(200, repos)
}
示例5: Build
func Build(tokens oauth2.Tokens, ctx *macaron.Context, req *http.Request) {
gh := github.New(tokens.Access())
user, err := gh.User()
if err != nil {
ctx.Error(500, err.Error())
return
}
muser := &models.User{
Name: user.Name,
Email: user.Email,
GithubToken: tokens.Access(),
Admin: false,
}
models.DB.Insert(muser)
// repos
var repos []*github.Repository
reposKey := "orgs:" + user.Login + ":repos"
if !rdx.Exists(reposKey).Val() || req.FormValue("refresh") != "" {
var err error
repos, err = gh.Repositories()
if err != nil {
ctx.Error(500, err.Error())
return
}
for _, repo := range repos {
rdx.HMSet(reposKey, repo.Fullname, "")
}
} else {
for _, repoName := range rdx.HKeys(reposKey).Val() {
repos = append(repos, &github.Repository{
Fullname: repoName,
})
}
}
// token
rdx.Set("user:"+user.Login+":github_token", tokens.Access(), 0)
tokenKey := "user:" + user.Login + ":token"
if !rdx.Exists(tokenKey).Val() {
rdx.Set(tokenKey, "gr"+goutils.RandNString(40), 0)
}
token := rdx.Get(tokenKey).Val()
rdx.Set("token:"+token+":user", user.Login, 0)
ctx.Data["User"] = user
ctx.Data["Token"] = token
ctx.Data["Repos"] = repos
ctx.HTML(200, "build")
}
示例6: AnonymousTriggerBuild
func AnonymousTriggerBuild(ctx *macaron.Context) {
r := ctx.Req
owner, repo := r.FormValue("owner"), r.FormValue("repo")
branch := r.FormValue("branch")
if owner == "" || repo == "" {
ctx.Error(500, "owner or repo should not be empty")
return
}
var mrepo = &models.Repository{
Owner: owner,
Repo: repo,
}
has, err := models.DB.Get(mrepo)
if err != nil {
ctx.Error(500, err.Error())
return
}
if has && mrepo.UserId != 0 {
ctx.Error(500, "This repo is limited to its author to build") // TODO: show who is owned
return
}
if err := triggerBuild(owner, repo, branch, "[email protected]"); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.JSON(200, map[string]string{
"message": "build is triggered",
})
}
示例7: Team
func Team(ctx *macaron.Context, locale i18n.Locale) {
ctx.Data["Link"] = "/team"
df := models.GetDoc(
"gitea",
"team",
locale.Lang)
if df == nil {
ctx.Error(404)
return
}
ctx.Data["Data"] = string(df.Data)
ctx.HTML(200, "page", ctx.Data)
}
示例8: Docs
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)
}
示例9: render
func render(ctx *macaron.Context, output []byte, err error, contentType string) {
if err != nil {
ctx.Error(500, err.Error()+"\n"+string(output))
return
}
if contentType == "" {
contentType = "text"
}
switch contentType {
case "html":
ctx.Header().Set("Content-Type", "text/html")
case "json":
ctx.Header().Set("Content-Type", "application/json; charset=UTF-8")
case "text":
ctx.Header().Set("Content-Type", "text/plain")
default:
ctx.Header().Set("Content-Type", contentType)
}
ctx.Write(output)
}
示例10: UserNeeded
func UserNeeded(tokens oauth2.Tokens, ctx *macaron.Context) {
user := &models.User{GithubToken: tokens.Access()}
has, err := models.DB.Get(user)
if err != nil {
ctx.Error(500, err.Error())
return
}
if !has {
gh := github.New(tokens.Access())
ghuser, err := gh.User()
if err != nil {
ctx.Error(500, err.Error())
return
}
user.Name = ghuser.Name
user.Email = ghuser.Email
user.Admin = false
models.DB.Insert(user)
}
ctx.Map(user)
}
示例11: TriggerBuild
func TriggerBuild(tokens oauth2.Tokens, ctx *macaron.Context) {
r := ctx.Req
owner, repo := r.FormValue("owner"), r.FormValue("repo")
branch := r.FormValue("branch")
gh := github.New(tokens.Access())
user, err := gh.User()
if err != nil {
ctx.Error(500, err.Error())
return
}
go func() {
err := models.TriggerTravisBuild(owner, repo, branch, user.Email)
if err != nil {
log.Println(err)
}
}()
ctx.JSON(200, map[string]string{
"message": "build is triggered",
})
}
示例12: UserRepoList
func UserRepoList(user *models.User, ctx *macaron.Context) {
if ctx.Req.Method == "POST" {
if time.Since(user.RepoUpdatedAt) > time.Minute {
if err := user.SyncGithub(); err != nil {
ctx.JSON(500, err.Error())
} else {
ctx.JSON(200, map[string]string{
"message": "sync github success",
})
}
} else {
ctx.JSON(200, map[string]string{
"message": "try after a minute",
})
}
return
}
if ctx.Req.Method != "GET" {
ctx.JSON(500, map[string]string{
"message": fmt.Sprintf("Method %s not supported", ctx.Req.Method),
})
return
}
repos, err := user.Repositories()
if err != nil {
ctx.Error(500, err.Error())
return
}
if len(repos) == 0 && time.Since(user.RepoUpdatedAt) > time.Hour*24 {
user.SyncGithub()
repos, _ = user.Repositories()
}
ctx.JSON(200, repos)
}
示例13: RepoBuild
func RepoBuild(user *models.User, ctx *macaron.Context) {
repo, err := getRepository(ctx.ParamsInt64(":id"))
if err != nil {
ctx.Error(500, err.Error())
return
}
branch := ctx.Req.FormValue("branch")
if ctx.Req.Method == "POST" {
err := triggerBuild(repo.Owner, repo.Repo, "", user.Email)
if err != nil {
ctx.Error(500, err.Error())
return
}
// dur := time.Since(repo.TriggerAt)
// var limitTime = time.Minute * 10
// if dur < limitTime { // too offen is not good
// ctx.Error(500, fmt.Sprintf("Too offen, retry after %v", limitTime-dur))
// return
// }
// repo.TriggerAt = time.Now()
// repo.Valid = true
// log.Println("%v", repo)
// models.DB.Id(repo.Id).Cols("trigger_at", "valid").Update(repo)
// go func() {
// err := models.TriggerTravisBuild(repo.Owner, repo.Repo, branch, user.Email)
// if err != nil {
// log.Println(err)
// }
// }()
ctx.JSON(200, map[string]string{
"message": fmt.Sprintf("build for repo: %s is triggered", strconv.Quote(repo.Owner+"/"+repo.Repo)),
})
return
}
if ctx.Req.Method == "PUT" {
if err := repo.AddBranch(branch); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.JSON(200, map[string]string{
"message": "change to valid",
})
return
}
// other methods
ctx.JSON(500, map[string]string{
"message": fmt.Sprintf("Method %s not supported", ctx.Req.Method),
})
}