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


Golang APIContext.Written方法代碼示例

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


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

示例1: CreateUser

// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#create-a-new-user
func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
	u := &models.User{
		Name:      form.Username,
		Email:     form.Email,
		Passwd:    form.Password,
		IsActive:  true,
		LoginType: models.LOGIN_PLAIN,
	}

	parseLoginSource(ctx, u, form.SourceID, form.LoginName)
	if ctx.Written() {
		return
	}

	if err := models.CreateUser(u); err != nil {
		if models.IsErrUserAlreadyExist(err) ||
			models.IsErrEmailAlreadyUsed(err) ||
			models.IsErrNameReserved(err) ||
			models.IsErrNamePatternNotAllowed(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "CreateUser", err)
		}
		return
	}
	log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)

	// Send e-mail notification.
	if form.SendNotify && setting.MailService != nil {
		mailer.SendRegisterNotifyMail(ctx.Context.Context, u)
	}

	ctx.JSON(201, convert.ToUser(u))
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:35,代碼來源:user.go

示例2: CreateOrg

// https://github.com/gigforks/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	org := &models.User{
		Name:        form.UserName,
		FullName:    form.FullName,
		Description: form.Description,
		Website:     form.Website,
		Location:    form.Location,
		IsActive:    true,
		Type:        models.USER_TYPE_ORGANIZATION,
	}
	if err := models.CreateOrganization(org, u); err != nil {
		if models.IsErrUserAlreadyExist(err) ||
			models.IsErrNameReserved(err) ||
			models.IsErrNamePatternNotAllowed(err) {
			ctx.Error(422, "", err)
		} else {
			ctx.Error(500, "CreateOrganization", err)
		}
		return
	}

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

示例3: ListFollowing

// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
func ListFollowing(ctx *context.APIContext) {
	u := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	listUserFollowing(ctx, u)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:8,代碼來源:follower.go

示例4: CheckMyFollowing

// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
func CheckMyFollowing(ctx *context.APIContext) {
	target := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	checkUserFollowing(ctx, ctx.User, target.Id)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:8,代碼來源:follower.go

示例5: 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

示例6: ListUserOrgs

// https://github.com/gigforks/go-gogs-client/wiki/Organizations#list-user-organizations
func ListUserOrgs(ctx *context.APIContext) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	listUserOrgs(ctx, u, false)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:8,代碼來源:org.go

示例7: CreatePublicKey

// https://github.com/gigforks/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	user.CreateUserPublicKey(ctx, form, u.Id)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:8,代碼來源:user.go

示例8: ListPublicKeys

// https://github.com/gigforks/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
func ListPublicKeys(ctx *context.APIContext) {
	user := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	listPublicKeys(ctx, user.Id)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:8,代碼來源:key.go

示例9: Get

// https://github.com/gigforks/go-gogs-client/wiki/Repositories#get
func Get(ctx *context.APIContext) {
	owner, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}

	ctx.JSON(200, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:9,代碼來源:repo.go

示例10: CreateRepo

// https://github.com/gigforks/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
func CreateRepo(ctx *context.APIContext, form api.CreateRepoOption) {
	owner := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	repo.CreateUserRepo(ctx, owner, form)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:9,代碼來源:repo.go

示例11: 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

示例12: CheckFollowing

// https://github.com/gigforks/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
func CheckFollowing(ctx *context.APIContext) {
	u := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	target := GetUserByParamsName(ctx, ":target")
	if ctx.Written() {
		return
	}
	checkUserFollowing(ctx, u, target.Id)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:12,代碼來源:follower.go

示例13: 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

示例14: 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

示例15: 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


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