1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

golint fixed for routers (#208)

This commit is contained in:
Lunny Xiao
2016-11-24 15:04:31 +08:00
committed by GitHub
parent 3a3782bb7f
commit 3917ed45de
35 changed files with 354 additions and 155 deletions

View File

@@ -11,7 +11,8 @@ import (
"code.gitea.io/gitea/modules/context"
)
// https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
// ListAccessTokens list all the access tokens
// see https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
func ListAccessTokens(ctx *context.APIContext) {
tokens, err := models.ListAccessTokens(ctx.User.ID)
if err != nil {
@@ -26,7 +27,8 @@ func ListAccessTokens(ctx *context.APIContext) {
ctx.JSON(200, &apiTokens)
}
// https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
// CreateAccessToken create access tokens
// see https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) {
t := &models.AccessToken{
UID: ctx.User.ID,

View File

@@ -13,7 +13,8 @@ import (
"code.gitea.io/gitea/routers/api/v1/convert"
)
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
// ListEmails list all the emails of mine
// see https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
func ListEmails(ctx *context.APIContext) {
emails, err := models.GetEmailAddresses(ctx.User.ID)
if err != nil {
@@ -27,7 +28,8 @@ func ListEmails(ctx *context.APIContext) {
ctx.JSON(200, &apiEmails)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
// AddEmail add email for me
// see https://github.com/gogits/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)
@@ -59,7 +61,8 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
ctx.JSON(201, &apiEmails)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
// DeleteEmail delete email
// see https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
func DeleteEmail(ctx *context.APIContext, form api.CreateEmailOption) {
if len(form.Emails) == 0 {
ctx.Status(204)

View File

@@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/modules/context"
)
func responseApiUsers(ctx *context.APIContext, users []*models.User) {
func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
apiUsers := make([]*api.User, len(users))
for i := range users {
apiUsers[i] = users[i].APIFormat()
@@ -25,14 +25,16 @@ func listUserFollowers(ctx *context.APIContext, u *models.User) {
ctx.Error(500, "GetUserFollowers", err)
return
}
responseApiUsers(ctx, users)
responseAPIUsers(ctx, users)
}
// ListMyFollowers list all my followers
func ListMyFollowers(ctx *context.APIContext) {
listUserFollowers(ctx, ctx.User)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
// ListFollowers list user's followers
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
func ListFollowers(ctx *context.APIContext) {
u := GetUserByParams(ctx)
if ctx.Written() {
@@ -47,14 +49,16 @@ func listUserFollowing(ctx *context.APIContext, u *models.User) {
ctx.Error(500, "GetFollowing", err)
return
}
responseApiUsers(ctx, users)
responseAPIUsers(ctx, users)
}
// ListMyFollowing list all my followings
func ListMyFollowing(ctx *context.APIContext) {
listUserFollowing(ctx, ctx.User)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
// ListFollowing list user's followings
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
func ListFollowing(ctx *context.APIContext) {
u := GetUserByParams(ctx)
if ctx.Written() {
@@ -71,7 +75,8 @@ func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64)
}
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
// CheckMyFollowing check if the repo is followed by me
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
func CheckMyFollowing(ctx *context.APIContext) {
target := GetUserByParams(ctx)
if ctx.Written() {
@@ -80,7 +85,8 @@ func CheckMyFollowing(ctx *context.APIContext) {
checkUserFollowing(ctx, ctx.User, target.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
// CheckFollowing check if the repo is followed by user
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
func CheckFollowing(ctx *context.APIContext) {
u := GetUserByParams(ctx)
if ctx.Written() {
@@ -93,7 +99,8 @@ func CheckFollowing(ctx *context.APIContext) {
checkUserFollowing(ctx, u, target.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
// Follow follow one repository
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
func Follow(ctx *context.APIContext) {
target := GetUserByParams(ctx)
if ctx.Written() {
@@ -106,7 +113,8 @@ func Follow(ctx *context.APIContext) {
ctx.Status(204)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
// Unfollow unfollow one repository
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
func Unfollow(ctx *context.APIContext) {
target := GetUserByParams(ctx)
if ctx.Written() {

View File

@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/repo"
)
// GetUserByParamsName get user by name
func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
user, err := models.GetUserByName(ctx.Params(name))
if err != nil {
@@ -52,12 +53,14 @@ func listPublicKeys(ctx *context.APIContext, uid int64) {
ctx.JSON(200, &apiKeys)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
// ListMyPublicKeys list all my public keys
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
func ListMyPublicKeys(ctx *context.APIContext) {
listPublicKeys(ctx, ctx.User.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
// ListPublicKeys list all user's public keys
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
func ListPublicKeys(ctx *context.APIContext) {
user := GetUserByParams(ctx)
if ctx.Written() {
@@ -66,7 +69,8 @@ func ListPublicKeys(ctx *context.APIContext) {
listPublicKeys(ctx, user.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
// GetPublicKey get one public key
// see https://github.com/gogits/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 {
@@ -99,12 +103,14 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
ctx.JSON(201, convert.ToPublicKey(apiLink, key))
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
// CreatePublicKey create one public key for me
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
CreateUserPublicKey(ctx, form, ctx.User.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
// DeletePublicKey delete one public key of mine
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
func DeletePublicKey(ctx *context.APIContext) {
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrKeyAccessDenied(err) {

View File

@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/context"
)
// Search search users
func Search(ctx *context.APIContext) {
opts := &models.SearchUserOptions{
Keyword: ctx.Query("q"),
@@ -51,6 +52,7 @@ func Search(ctx *context.APIContext) {
})
}
// GetInfo get user's information
func GetInfo(ctx *context.APIContext) {
u, err := models.GetUserByName(ctx.Params(":username"))
if err != nil {
@@ -69,6 +71,7 @@ func GetInfo(ctx *context.APIContext) {
ctx.JSON(200, u.APIFormat())
}
// GetAuthenticatedUser get curent user's information
func GetAuthenticatedUser(ctx *context.APIContext) {
ctx.JSON(200, ctx.User.APIFormat())
}