Skip to content

Commit a843466

Browse files
committed
dont use "com.ToStr()"
1 parent 283c6df commit a843466

File tree

16 files changed

+51
-60
lines changed

16 files changed

+51
-60
lines changed

cmd/serv.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"github.com/dgrijalva/jwt-go"
2828
"github.com/kballard/go-shellquote"
29-
"github.com/unknwon/com"
3029
"github.com/urfave/cli"
3130
)
3231

@@ -105,7 +104,10 @@ func runServ(c *cli.Context) error {
105104
if len(keys) != 2 || keys[0] != "key" {
106105
fail("Key ID format error", "Invalid key argument: %s", c.Args()[0])
107106
}
108-
keyID := com.StrTo(keys[1]).MustInt64()
107+
keyID, err := strconv.ParseInt(keys[1], 10, 64)
108+
if err != nil {
109+
fail("Key ID format error", "Invalid key argument: %s", c.Args()[1])
110+
}
109111

110112
cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
111113
if len(cmd) == 0 {

modules/base/tool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool {
8686
// split code
8787
start := code[:12]
8888
lives := code[12:18]
89-
if d, err := com.StrTo(lives).Int(); err == nil {
90-
minutes = d
89+
if d, err := strconv.ParseInt(lives, 10, 0); err == nil {
90+
minutes = int(d)
9191
}
9292

9393
// right active code
@@ -223,7 +223,7 @@ func TruncateString(str string, limit int) string {
223223
func StringsToInt64s(strs []string) ([]int64, error) {
224224
ints := make([]int64, len(strs))
225225
for i := range strs {
226-
n, err := com.StrTo(strs[i]).Int64()
226+
n, err := strconv.ParseInt(strs[i], 10, 64)
227227
if err != nil {
228228
return ints, err
229229
}

modules/convert/convert.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
api "code.gitea.io/gitea/modules/structs"
1818
"code.gitea.io/gitea/modules/util"
1919
"code.gitea.io/gitea/services/webhook"
20-
21-
"github.com/unknwon/com"
2220
)
2321

2422
// ToEmail convert models.EmailAddress to api.Email
@@ -169,7 +167,7 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
169167
return &api.PublicKey{
170168
ID: key.ID,
171169
Key: key.Content,
172-
URL: apiLink + com.ToStr(key.ID),
170+
URL: fmt.Sprintf("%s%d", apiLink, key.ID),
173171
Title: key.Name,
174172
Fingerprint: key.Fingerprint,
175173
Created: key.CreatedUnix.AsTime(),
@@ -263,7 +261,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
263261
KeyID: key.KeyID,
264262
Key: key.Content,
265263
Fingerprint: key.Fingerprint,
266-
URL: apiLink + com.ToStr(key.ID),
264+
URL: fmt.Sprintf("%s%d", apiLink, key.ID),
267265
Title: key.Name,
268266
Created: key.CreatedUnix.AsTime(),
269267
ReadOnly: key.Mode == models.AccessModeRead, // All deploy keys are read-only.

modules/git/repo.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"strconv"
1616
"strings"
1717
"time"
18-
19-
"github.com/unknwon/com"
2018
)
2119

2220
// GPGSettings represents the default GPG settings for this repository
@@ -309,21 +307,24 @@ func parseSize(objects string) *CountObject {
309307
for _, line := range strings.Split(objects, "\n") {
310308
switch {
311309
case strings.HasPrefix(line, statCount):
312-
repoSize.Count = com.StrTo(line[7:]).MustInt64()
310+
repoSize.Count, _ = strconv.ParseInt(line[7:], 10, 64)
313311
case strings.HasPrefix(line, statSize):
314-
repoSize.Size = com.StrTo(line[6:]).MustInt64() * 1024
312+
repoSize.Size, _ = strconv.ParseInt(line[6:], 10, 64)
313+
repoSize.Size *= 1024
315314
case strings.HasPrefix(line, statInpack):
316-
repoSize.InPack = com.StrTo(line[9:]).MustInt64()
315+
repoSize.InPack, _ = strconv.ParseInt(line[9:], 10, 64)
317316
case strings.HasPrefix(line, statPacks):
318-
repoSize.Packs = com.StrTo(line[7:]).MustInt64()
317+
repoSize.Packs, _ = strconv.ParseInt(line[7:], 10, 64)
319318
case strings.HasPrefix(line, statSizePack):
320-
repoSize.SizePack = com.StrTo(line[11:]).MustInt64() * 1024
319+
repoSize.Count, _ = strconv.ParseInt(line[11:], 10, 64)
320+
repoSize.Count *= 1024
321321
case strings.HasPrefix(line, statPrunePackage):
322-
repoSize.PrunePack = com.StrTo(line[16:]).MustInt64()
322+
repoSize.PrunePack, _ = strconv.ParseInt(line[16:], 10, 64)
323323
case strings.HasPrefix(line, statGarbage):
324-
repoSize.Garbage = com.StrTo(line[9:]).MustInt64()
324+
repoSize.Garbage, _ = strconv.ParseInt(line[9:], 10, 64)
325325
case strings.HasPrefix(line, statSizeGarbage):
326-
repoSize.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024
326+
repoSize.SizeGarbage, _ = strconv.ParseInt(line[14:], 10, 64)
327+
repoSize.SizeGarbage *= 1024
327328
}
328329
}
329330
return repoSize

modules/ssh/ssh.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"code.gitea.io/gitea/modules/util"
2626

2727
"github.com/gliderlabs/ssh"
28-
"github.com/unknwon/com"
2928
gossh "golang.org/x/crypto/ssh"
3029
)
3130

@@ -58,13 +57,13 @@ func getExitStatusFromError(err error) int {
5857
}
5958

6059
func sessionHandler(session ssh.Session) {
61-
keyID := session.Context().Value(giteaKeyID).(int64)
60+
keyID := fmt.Sprintf("%d", session.Context().Value(giteaKeyID).(int64))
6261

6362
command := session.RawCommand()
6463

6564
log.Trace("SSH: Payload: %v", command)
6665

67-
args := []string{"serv", "key-" + com.ToStr(keyID), "--config=" + setting.CustomConf}
66+
args := []string{"serv", "key-" + keyID, "--config=" + setting.CustomConf}
6867
log.Trace("SSH: Arguments: %v", args)
6968
cmd := exec.Command(setting.AppPath, args...)
7069
cmd.Env = append(

routers/admin/emails.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/util"
17-
18-
"github.com/unknwon/com"
1917
)
2018

2119
const (
@@ -114,7 +112,7 @@ func ActivateEmail(ctx *context.Context) {
114112

115113
truefalse := map[string]bool{"1": true, "0": false}
116114

117-
uid := com.StrTo(ctx.Query("uid")).MustInt64()
115+
uid := ctx.QueryInt64("uid")
118116
email := ctx.Query("email")
119117
primary, okp := truefalse[ctx.Query("primary")]
120118
activate, oka := truefalse[ctx.Query("activate")]

routers/admin/notice.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/context"
1212
"code.gitea.io/gitea/modules/log"
1313
"code.gitea.io/gitea/modules/setting"
14-
15-
"github.com/unknwon/com"
14+
"strconv"
1615
)
1716

1817
const (
@@ -50,7 +49,7 @@ func DeleteNotices(ctx *context.Context) {
5049
strs := ctx.QueryStrings("ids[]")
5150
ids := make([]int64, 0, len(strs))
5251
for i := range strs {
53-
id := com.StrTo(strs[i]).MustInt64()
52+
id, _ := strconv.ParseInt(strs[i], 10, 64)
5453
if id > 0 {
5554
ids = append(ids, id)
5655
}

routers/admin/users.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package admin
77

88
import (
9+
"strconv"
910
"strings"
1011

1112
"code.gitea.io/gitea/models"
@@ -92,8 +93,9 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
9293
if len(form.LoginType) > 0 {
9394
fields := strings.Split(form.LoginType, "-")
9495
if len(fields) == 2 {
95-
u.LoginType = models.LoginType(com.StrTo(fields[0]).MustInt())
96-
u.LoginSource = com.StrTo(fields[1]).MustInt64()
96+
lType, _ := strconv.ParseInt(fields[0], 10, 0)
97+
u.LoginType = models.LoginType(lType)
98+
u.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64)
9799
u.LoginName = form.LoginName
98100
}
99101
}
@@ -220,12 +222,12 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
220222

221223
fields := strings.Split(form.LoginType, "-")
222224
if len(fields) == 2 {
223-
loginType := models.LoginType(com.StrTo(fields[0]).MustInt())
224-
loginSource := com.StrTo(fields[1]).MustInt64()
225+
loginType, _ := strconv.ParseInt(fields[0], 10, 0)
226+
loginSource, _ := strconv.ParseInt(fields[1], 10, 64)
225227

226228
if u.LoginSource != loginSource {
227229
u.LoginSource = loginSource
228-
u.LoginType = loginType
230+
u.LoginType = models.LoginType(loginType)
229231
}
230232
}
231233

routers/api/v1/user/user.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ package user
88
import (
99
"fmt"
1010
"net/http"
11+
"strconv"
1112
"strings"
1213

1314
"code.gitea.io/gitea/models"
1415
"code.gitea.io/gitea/modules/context"
1516
"code.gitea.io/gitea/modules/convert"
1617
api "code.gitea.io/gitea/modules/structs"
1718
"code.gitea.io/gitea/routers/api/v1/utils"
18-
19-
"github.com/unknwon/com"
2019
)
2120

2221
// Search search users
@@ -59,9 +58,14 @@ func Search(ctx *context.APIContext) {
5958

6059
listOptions := utils.GetListOptions(ctx)
6160

61+
uid, err := strconv.ParseInt(ctx.Query("uid"), 10, 64)
62+
if err != nil {
63+
ctx.Error(http.StatusUnprocessableEntity, "uid", err)
64+
}
65+
6266
opts := &models.SearchUserOptions{
6367
Keyword: strings.Trim(ctx.Query("q"), " "),
64-
UID: com.StrTo(ctx.Query("uid")).MustInt64(),
68+
UID: uid,
6569
Type: models.UserTypeIndividual,
6670
ListOptions: listOptions,
6771
}

routers/org/members.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"code.gitea.io/gitea/modules/context"
1212
"code.gitea.io/gitea/modules/log"
1313
"code.gitea.io/gitea/modules/setting"
14-
15-
"github.com/unknwon/com"
1614
)
1715

1816
const (
@@ -70,7 +68,7 @@ func Members(ctx *context.Context) {
7068

7169
// MembersAction response for operation to a member of organization
7270
func MembersAction(ctx *context.Context) {
73-
uid := com.StrTo(ctx.Query("uid")).MustInt64()
71+
uid := ctx.QueryInt64("uid")
7472
if uid == 0 {
7573
ctx.Redirect(ctx.Org.OrgLink + "/members")
7674
return

routers/org/teams.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/context"
1717
"code.gitea.io/gitea/modules/log"
1818
"code.gitea.io/gitea/routers/utils"
19-
20-
"github.com/unknwon/com"
2119
)
2220

2321
const (
@@ -50,7 +48,7 @@ func Teams(ctx *context.Context) {
5048

5149
// TeamsAction response for join, leave, remove, add operations to team
5250
func TeamsAction(ctx *context.Context) {
53-
uid := com.StrTo(ctx.Query("uid")).MustInt64()
51+
uid := ctx.QueryInt64("uid")
5452
if uid == 0 {
5553
ctx.Redirect(ctx.Org.OrgLink + "/teams")
5654
return
@@ -155,7 +153,7 @@ func TeamsRepoAction(ctx *context.Context) {
155153
}
156154
err = ctx.Org.Team.AddRepository(repo)
157155
case "remove":
158-
err = ctx.Org.Team.RemoveRepository(com.StrTo(ctx.Query("repoid")).MustInt64())
156+
err = ctx.Org.Team.RemoveRepository(ctx.QueryInt64("repoid"))
159157
case "addall":
160158
err = ctx.Org.Team.AddAllRepositories()
161159
case "removeall":

routers/repo/lfs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import (
2626
"code.gitea.io/gitea/modules/log"
2727
"code.gitea.io/gitea/modules/setting"
2828
"code.gitea.io/gitea/modules/storage"
29-
30-
"github.com/unknwon/com"
3129
)
3230

3331
const (
@@ -579,7 +577,7 @@ func LFSAutoAssociate(ctx *context.Context) {
579577
}
580578
var err error
581579
metas[i] = &models.LFSMetaObject{}
582-
metas[i].Size, err = com.StrTo(oid[idx+1:]).Int64()
580+
metas[i].Size, err = strconv.ParseInt(oid[idx+1:], 10, 64)
583581
if err != nil {
584582
ctx.ServerError("LFSAutoAssociate", fmt.Errorf("Illegal oid input: %s %v", oid, err))
585583
return

services/mirror/mirror.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"net/url"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -22,8 +23,6 @@ import (
2223
"code.gitea.io/gitea/modules/sync"
2324
"code.gitea.io/gitea/modules/timeutil"
2425
"code.gitea.io/gitea/modules/util"
25-
26-
"github.com/unknwon/com"
2726
)
2827

2928
// mirrorQueue holds an UniqueQueue object of the mirror
@@ -396,11 +395,11 @@ func syncMirror(repoID string) {
396395
}()
397396
mirrorQueue.Remove(repoID)
398397

399-
m, err := models.GetMirrorByRepoID(com.StrTo(repoID).MustInt64())
398+
id, _ := strconv.ParseInt(repoID, 10, 64)
399+
m, err := models.GetMirrorByRepoID(id)
400400
if err != nil {
401401
log.Error("GetMirrorByRepoID [%s]: %v", repoID, err)
402402
return
403-
404403
}
405404

406405
log.Trace("SyncMirrors [repo: %-v]: Running Sync", m.Repo)

services/pull/check.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"code.gitea.io/gitea/modules/queue"
2222
"code.gitea.io/gitea/modules/timeutil"
2323
"code.gitea.io/gitea/modules/util"
24-
25-
"github.com/unknwon/com"
2624
)
2725

2826
// prQueue represents a queue to handle update pull request tests
@@ -203,14 +201,13 @@ func InitializePullRequests(ctx context.Context) {
203201
// handle passed PR IDs and test the PRs
204202
func handle(data ...queue.Data) {
205203
for _, datum := range data {
206-
prID := datum.(string)
207-
id := com.StrTo(prID).MustInt64()
204+
id, _ := strconv.ParseInt(datum.(string), 10, 64)
208205

209206
log.Trace("Testing PR ID %d from the pull requests patch checking queue", id)
210207

211208
pr, err := models.GetPullRequestByID(id)
212209
if err != nil {
213-
log.Error("GetPullRequestByID[%s]: %v", prID, err)
210+
log.Error("GetPullRequestByID[%s]: %v", datum, err)
214211
continue
215212
} else if pr.HasMerged {
216213
continue

services/pull/check_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"code.gitea.io/gitea/modules/queue"
1616

1717
"github.com/stretchr/testify/assert"
18-
"github.com/unknwon/com"
1918
)
2019

2120
func TestPullRequest_AddToTaskQueue(t *testing.T) {
@@ -25,8 +24,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
2524

2625
q, err := queue.NewChannelUniqueQueue(func(data ...queue.Data) {
2726
for _, datum := range data {
28-
prID := datum.(string)
29-
id := com.StrTo(prID).MustInt64()
27+
id, _ := strconv.ParseInt(datum.(string), 10, 64)
3028
idChan <- id
3129
}
3230
}, queue.ChannelUniqueQueueConfiguration{

0 commit comments

Comments
 (0)