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


Golang context.APIContext類代碼示例

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


在下文中一共展示了APIContext類的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: 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

示例3: responseApiUsers

func responseApiUsers(ctx *context.APIContext, users []*models.User) {
	apiUsers := make([]*api.User, len(users))
	for i := range users {
		apiUsers[i] = convert.ToUser(users[i])
	}
	ctx.JSON(200, &apiUsers)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:7,代碼來源:follower.go

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

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

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

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

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

示例9: HandleCheckKeyStringError

func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
	if models.IsErrKeyUnableVerify(err) {
		ctx.Error(422, "", "Unable to verify key content")
	} else {
		ctx.Error(422, "", fmt.Errorf("Invalid key content: %v", err))
	}
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:7,代碼來源:key.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: Create

// https://github.com/gigforks/go-gogs-client/wiki/Repositories#create
func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
	// Shouldn't reach this condition, but just in case.
	if ctx.User.IsOrganization() {
		ctx.Error(422, "", "not allowed creating repository for organization")
		return
	}
	CreateUserRepo(ctx, ctx.User, opt)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:9,代碼來源:repo.go

示例12: MarkdownRaw

// https://github.com/gigforks/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
func MarkdownRaw(ctx *context.APIContext) {
	body, err := ctx.Req.Body().Bytes()
	if err != nil {
		ctx.Error(422, "", err)
		return
	}
	ctx.Write(markdown.RenderRaw(body, ""))
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:9,代碼來源:markdown.go

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

示例14: listUserFollowing

func listUserFollowing(ctx *context.APIContext, u *models.User) {
	users, err := u.GetFollowing(ctx.QueryInt("page"))
	if err != nil {
		ctx.Error(500, "GetFollowing", err)
		return
	}
	responseApiUsers(ctx, users)
}
開發者ID:gigforks,項目名稱:gogs,代碼行數:8,代碼來源:follower.go

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


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