本文整理匯總了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)
}
示例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)
}
示例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)
}
示例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)
}
示例5: checkUserFollowing
func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) {
if u.IsFollowing(followID) {
ctx.Status(204)
} else {
ctx.Status(404)
}
}
示例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)
}
示例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)
}
示例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)
}
示例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))
}
}
示例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)
}
示例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)
}
示例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, ""))
}
示例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}))
}
示例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)
}
示例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)
}