本文整理匯總了Golang中github.com/pecastro/gogs/modules/middleware.Context.WriteHeader方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.WriteHeader方法的具體用法?Golang Context.WriteHeader怎麽用?Golang Context.WriteHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pecastro/gogs/modules/middleware.Context
的用法示例。
在下文中一共展示了Context.WriteHeader方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MigrateRepo
func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
u, err := models.GetUserByName(ctx.Query("username"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.HandleAPI(422, err)
} else {
ctx.HandleAPI(500, err)
}
return
}
if !u.ValidatePassword(ctx.Query("password")) {
ctx.HandleAPI(422, "Username or password is not correct.")
return
}
ctxUser := u
// Not equal means current user is an organization.
if form.Uid != u.Id {
org, err := models.GetUserByID(form.Uid)
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.HandleAPI(422, err)
} else {
ctx.HandleAPI(500, err)
}
return
}
ctxUser = org
}
if ctx.HasError() {
ctx.HandleAPI(422, ctx.GetErrMsg())
return
}
if ctxUser.IsOrganization() {
// Check ownership of organization.
if !ctxUser.IsOwnedBy(u.Id) {
ctx.HandleAPI(403, "Given user is not owner of organization.")
return
}
}
// Remote address can be HTTP/HTTPS/Git URL or local path.
remoteAddr := form.CloneAddr
if strings.HasPrefix(form.CloneAddr, "http://") ||
strings.HasPrefix(form.CloneAddr, "https://") ||
strings.HasPrefix(form.CloneAddr, "git://") {
u, err := url.Parse(form.CloneAddr)
if err != nil {
ctx.HandleAPI(422, err)
return
}
if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 {
u.User = url.UserPassword(form.AuthUsername, form.AuthPassword)
}
remoteAddr = u.String()
} else if !com.IsDir(remoteAddr) {
ctx.HandleAPI(422, "Invalid local path, it does not exist or not a directory.")
return
}
repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
if err != nil {
if repo != nil {
if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
ctx.HandleAPI(500, err)
return
}
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
ctx.WriteHeader(200)
}