// Copyright 2014 The Gogs Authors. All rights reserved.// Use of this source code is governed by a MIT-style// license that can be found in the LICENSE file.packageuserimport("net/http"api"github.com/gogs/go-gogs-client""gogs.io/gogs/internal/context""gogs.io/gogs/internal/db")funcListAccessTokens(c*context.APIContext){tokens,err:=db.AccessTokens.List(c.Req.Context(),c.User.ID)iferr!=nil{c.Error(err,"list access tokens")return}apiTokens:=make([]*api.AccessToken,len(tokens))fori:=rangetokens{apiTokens[i]=&api.AccessToken{Name:tokens[i].Name,Sha1:tokens[i].Sha1}}c.JSONSuccess(&apiTokens)}funcCreateAccessToken(c*context.APIContext,formapi.CreateAccessTokenOption){t,err:=db.AccessTokens.Create(c.Req.Context(),c.User.ID,form.Name)iferr!=nil{ifdb.IsErrAccessTokenAlreadyExist(err){c.ErrorStatus(http.StatusUnprocessableEntity,err)}else{c.Error(err,"new access token")}return}c.JSON(http.StatusCreated,&api.AccessToken{Name:t.Name,Sha1:t.Sha1})}