當前位置: 首頁>>代碼示例>>Golang>>正文


Golang APIContext.Status方法代碼示例

本文整理匯總了Golang中github.com/gigforks/gogs/modules/context.APIContext.Status方法的典型用法代碼示例。如果您正苦於以下問題:Golang APIContext.Status方法的具體用法?Golang APIContext.Status怎麽用?Golang APIContext.Status使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gigforks/gogs/modules/context.APIContext的用法示例。


在下文中一共展示了APIContext.Status方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RemoveUserAccess

func RemoveUserAccess(ctx *context.APIContext) {
	owner, repo := parseOwnerAndRepo(ctx)

	if ctx.Written() {
		return
	}

	repo.Owner = owner

	u, err := models.GetUserByName(ctx.Params(":user"))

	if err != nil {
		ctx.Error(404, "user does not exist", err)
		return
	}

	err = repo.DeleteCollaboration(u.Id)

	if err != nil {
		ctx.Error(500, "delete collab", err)
		return
	}

	ctx.Status(204)

}
開發者ID:gigforks,項目名稱:gogs,代碼行數:26,代碼來源:repo.go

示例2: AddEmail

// https://github.com/gigforks/go-gogs-client/wiki/Users-Emails#add-email-addresses
func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
	if len(form.Emails) == 0 {
		ctx.Status(422)
		return
	}

	emails := make([]*models.EmailAddress, len(form.Emails))
	for i := range form.Emails {
		emails[i] = &models.EmailAddress{
			UID:         ctx.User.Id,
			Email:       form.Emails[i],
			IsActivated: !setting.Service.RegisterEmailConfirm,
		}
	}

	if err := models.AddEmailAddresses(emails); err != nil {
		if models.IsErrEmailAlreadyUsed(err) {
			ctx.Error(422, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
		} else {
			ctx.Error(500, "AddEmailAddresses", err)
		}
		return
	}

	apiEmails := make([]*api.Email, len(emails))
	for i := range emails {
		apiEmails[i] = convert.ToEmail(emails[i])
	}
	ctx.JSON(201, &apiEmails)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:31,代碼來源:email.go

示例3: checkUserFollowing

func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) {
	if u.IsFollowing(followID) {
		ctx.Status(204)
	} else {
		ctx.Status(404)
	}
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:7,代碼來源:follower.go

示例4: Follow

// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#follow-a-user
func Follow(ctx *context.APIContext) {
	target := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := models.FollowUser(ctx.User.Id, target.Id); err != nil {
		ctx.Error(500, "FollowUser", err)
		return
	}
	ctx.Status(204)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:12,代碼來源:follower.go

示例5: DeleteDeploykey

// https://github.com/gigforks/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
func DeleteDeploykey(ctx *context.APIContext) {
	if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
		if models.IsErrKeyAccessDenied(err) {
			ctx.Error(403, "", "You do not have access to this key")
		} else {
			ctx.Error(500, "DeleteDeployKey", err)
		}
		return
	}

	ctx.Status(204)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:13,代碼來源:key.go

示例6: AddTeamMember

func AddTeamMember(ctx *context.APIContext) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := ctx.Org.Team.AddMember(u.Id); err != nil {
		ctx.Error(500, "AddMember", err)
		return
	}

	ctx.Status(204)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:12,代碼來源:org_team.go

示例7: GetUserByParamsName

func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
	user, err := models.GetUserByName(ctx.Params(name))
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.Status(404)
		} else {
			ctx.Error(500, "GetUserByName", err)
		}
		return nil
	}
	return user
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:12,代碼來源:key.go

示例8: RemoveTeamRepository

func RemoveTeamRepository(ctx *context.APIContext) {
	repo := GetRepositoryByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := ctx.Org.Team.RemoveRepository(repo.ID); err != nil {
		ctx.Error(500, "RemoveRepository", err)
		return
	}

	ctx.Status(204)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:12,代碼來源:org_repo.go

示例9: GetRepositoryByParams

func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
	repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
	if err != nil {
		if models.IsErrRepoNotExist(err) {
			ctx.Status(404)
		} else {
			ctx.Error(500, "GetRepositoryByName", err)
		}
		return nil
	}
	return repo
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:12,代碼來源:org_repo.go

示例10: GetIssue

func GetIssue(ctx *context.APIContext) {
	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
	if err != nil {
		if models.IsErrIssueNotExist(err) {
			ctx.Status(404)
		} else {
			ctx.Error(500, "GetIssueByIndex", err)
		}
		return
	}

	ctx.JSON(200, convert.ToIssue(issue))
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:13,代碼來源:issue.go

示例11: GetPublicKey

// https://github.com/gigforks/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
func GetPublicKey(ctx *context.APIContext) {
	key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if models.IsErrKeyNotExist(err) {
			ctx.Status(404)
		} else {
			ctx.Error(500, "GetPublicKeyByID", err)
		}
		return
	}

	apiLink := composePublicKeysAPILink()
	ctx.JSON(200, convert.ToPublicKey(apiLink, key))
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:15,代碼來源:key.go

示例12: DeleteOrg

func DeleteOrg(ctx *context.APIContext) {
	org := user.GetUserByParamsName(ctx, ":orgname")

	if ctx.Written() {
		return
	}

	err := models.DeleteOrganization(org)

	if err != nil {
		ctx.Error(500, "", err)
	}
	ctx.Status(204)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:14,代碼來源:org.go

示例13: GetInfo

// https://github.com/gigforks/go-gogs-client/wiki/Users#get-a-single-user
func GetInfo(ctx *context.APIContext) {
	u, err := models.GetUserByName(ctx.Params(":username"))
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.Status(404)
		} else {
			ctx.Error(500, "GetUserByName", err)
		}
		return
	}

	// Hide user e-mail when API caller isn't signed in.
	if !ctx.IsSigned {
		u.Email = ""
	}
	ctx.JSON(200, &api.User{u.Id, u.Name, u.FullName, u.Email, u.AvatarLink()})
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:18,代碼來源:user.go

示例14: Edit

// https://github.com/gigforks/go-gogs-client/wiki/Organizations#edit-an-organization
func Edit(ctx *context.APIContext, form api.EditOrgOption) {
	org := ctx.Org.Organization
	if !org.IsOwnedBy(ctx.User.Id) {
		ctx.Status(403)
		return
	}

	org.FullName = form.FullName
	org.Description = form.Description
	org.Website = form.Website
	org.Location = form.Location
	if err := models.UpdateUser(org); err != nil {
		ctx.Error(500, "UpdateUser", err)
		return
	}

	ctx.JSON(200, convert.ToOrganization(org))
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:19,代碼來源:org.go

示例15: DeleteUser

// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#delete-a-user
func DeleteUser(ctx *context.APIContext) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	if err := models.DeleteUser(u); err != nil {
		if models.IsErrUserOwnRepos(err) ||
			models.IsErrUserHasOrgs(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "DeleteUser", err)
		}
		return
	}
	log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name)

	ctx.Status(204)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:20,代碼來源:user.go


注:本文中的github.com/gigforks/gogs/modules/context.APIContext.Status方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。