Skip to content

Commit 1db672c

Browse files
committed
change size to limit
1 parent c48cf12 commit 1db672c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+353
-297
lines changed

api/types/types.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ option go_package = "github.com/zhufuyi/sponge/api/types;types";
66

77
message Params {
88
int32 page = 1; // page number, starting from 0
9-
int32 limit = 2; // lines per page
9+
int32 limit = 2; // number per page
1010
string sort = 3; // sorted fields, multi-column sorting separated by commas
1111
repeated Column columns = 4; // query conditions
1212
}

cmd/protoc-gen-go-gin/internal/parse/method.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package parse
22

33
import (
44
"fmt"
5+
"net/http"
56
"strings"
67

78
"google.golang.org/genproto/googleapis/api/annotations"
@@ -39,23 +40,23 @@ func buildHTTPRule(m *protogen.Method, rule *annotations.HttpRule) *RPCMethod {
3940
switch pattern := rule.Pattern.(type) {
4041
case *annotations.HttpRule_Get:
4142
path = pattern.Get
42-
method = "GET"
43+
method = http.MethodGet
4344
case *annotations.HttpRule_Put:
4445
path = pattern.Put
45-
method = "PUT"
46+
method = http.MethodPut
4647
case *annotations.HttpRule_Post:
4748
path = pattern.Post
48-
method = "POST"
49+
method = http.MethodPost
4950
case *annotations.HttpRule_Delete:
5051
path = pattern.Delete
51-
method = "DELETE"
52+
method = http.MethodDelete
5253
case *annotations.HttpRule_Patch:
5354
path = pattern.Patch
54-
method = "PATCH"
55+
method = http.MethodPatch
5556
case *annotations.HttpRule_Custom:
5657
path = pattern.Custom.Path
5758
customKind = strings.ToLower(pattern.Custom.Kind)
58-
method = "POST" // default
59+
method = http.MethodPost // default
5960
}
6061
md := buildMethodDesc(m, method, path, customKind, selector)
6162
return md
@@ -158,25 +159,25 @@ func (m *RPCMethod) checkCustomKind() {
158159

159160
switch customKindStr {
160161
case "get":
161-
m.Method = "GET"
162+
m.Method = http.MethodGet
162163
case "post":
163-
m.Method = "POST"
164+
m.Method = http.MethodPost
164165
case "put":
165-
m.Method = "PUT"
166+
m.Method = http.MethodPut
166167
case "delete":
167-
m.Method = "DELETE"
168+
m.Method = http.MethodDelete
168169
case "patch":
169-
m.Method = "PATCH"
170+
m.Method = http.MethodPatch
170171
case "options":
171-
m.Method = "OPTIONS"
172+
m.Method = http.MethodOptions
172173
case "head":
173-
m.Method = "HEAD"
174+
m.Method = http.MethodHead
174175
case "trace":
175-
m.Method = "TRACE"
176+
m.Method = http.MethodTrace
176177
case "connect":
177-
m.Method = "CONNECT"
178+
m.Method = http.MethodConnect
178179
default:
179-
m.Method = "POST"
180+
m.Method = http.MethodPost
180181
}
181182
}
182183

docs/docs.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/swagger.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@
309309
"$ref": "#/definitions/github_com_zhufuyi_sponge_internal_types.Column"
310310
}
311311
},
312-
"page": {
313-
"description": "page number, starting from page 0",
312+
"limit": {
313+
"description": "lines per page",
314314
"type": "integer"
315315
},
316-
"size": {
317-
"description": "lines per page",
316+
"page": {
317+
"description": "page number, starting from page 0",
318318
"type": "integer"
319319
},
320320
"sort": {

docs/swagger.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ definitions:
2222
items:
2323
$ref: '#/definitions/github_com_zhufuyi_sponge_internal_types.Column'
2424
type: array
25+
limit:
26+
description: lines per page
27+
type: integer
2528
page:
2629
description: page number, starting from page 0
2730
type: integer
28-
size:
29-
description: lines per page
30-
type: integer
3131
sort:
3232
description: sorted fields, multi-column sorting separated by commas
3333
type: string

internal/dao/userExample.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id uint64) (*model.UserExa
182182
// paging parameters (required):
183183
//
184184
// page: page number, starting from 0
185-
// size: lines per page
185+
// limit: lines per page
186186
// sort: sort fields, default is id backwards, you can add - sign before the field to indicate reverse order, no - sign to indicate ascending order, multiple fields separated by comma
187187
//
188188
// query parameters (not required):
@@ -196,7 +196,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id uint64) (*model.UserExa
196196
//
197197
// params = &query.Params{
198198
// Page: 0,
199-
// Size: 20,
199+
// Limit: 20,
200200
// Columns: []query.Column{
201201
// {
202202
// Name: "age",

internal/dao/userExample.go.exp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id uint64) (*model.UserExa
188188
// paging parameters (required):
189189
//
190190
// page: page number, starting from 0
191-
// size: lines per page
191+
// limit: lines per page
192192
// sort: sort fields, default is id backwards, you can add - sign before the field to indicate reverse order, no - sign to indicate ascending order, multiple fields separated by comma
193193
//
194194
// query parameters (not required):
@@ -202,7 +202,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id uint64) (*model.UserExa
202202
//
203203
// params = &query.Params{
204204
// Page: 0,
205-
// Size: 20,
205+
// Limit: 20,
206206
// Columns: []query.Column{
207207
// {
208208
// Name: "age",
@@ -366,7 +366,7 @@ func (d *userExampleDao) GetByLastID(ctx context.Context, lastID uint64, limit i
366366
page := query.NewPage(0, limit, sort)
367367

368368
records := []*model.UserExample{}
369-
err := d.db.WithContext(ctx).Order(page.Sort()).Limit(page.Size()).Where("id < ?", lastID).Find(&records).Error
369+
err := d.db.WithContext(ctx).Order(page.Sort()).Limit(page.Limit()).Where("id < ?", lastID).Find(&records).Error
370370
if err != nil {
371371
return nil, err
372372
}

internal/dao/userExample.go.mgo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id string) (*model.UserExa
200200
// paging parameters (required):
201201
//
202202
// page: page number, starting from 0
203-
// size: lines per page
203+
// limit: lines per page
204204
// sort: sort fields, default is id backwards, you can add - sign before the field to indicate reverse order, no - sign to indicate ascending order, multiple fields separated by comma
205205
//
206206
// query parameters (not required):
@@ -214,7 +214,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id string) (*model.UserExa
214214
//
215215
// params = &query.Params{
216216
// Page: 0,
217-
// Size: 20,
217+
// Limit: 20,
218218
// Columns: []query.Column{
219219
// {
220220
// Name: "age",

internal/dao/userExample.go.mgo.exp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id string) (*model.UserExa
205205
// paging parameters (required):
206206
//
207207
// page: page number, starting from 0
208-
// size: lines per page
208+
// limit: lines per page
209209
// sort: sort fields, default is id backwards, you can add - sign before the field to indicate reverse order, no - sign to indicate ascending order, multiple fields separated by comma
210210
//
211211
// query parameters (not required):
@@ -219,7 +219,7 @@ func (d *userExampleDao) GetByID(ctx context.Context, id string) (*model.UserExa
219219
//
220220
// params = &query.Params{
221221
// Page: 0,
222-
// Size: 20,
222+
// Limit: 20,
223223
// Columns: []query.Column{
224224
// {
225225
// Name: "age",
@@ -401,7 +401,7 @@ func (d *userExampleDao) GetByLastID(ctx context.Context, lastID string, limit i
401401
page := query.NewPage(0, limit, sort)
402402

403403
findOpts := new(options.FindOptions)
404-
findOpts.SetLimit(int64(page.Size())).SetSkip(int64(page.Skip()))
404+
findOpts.SetLimit(int64(page.Limit())).SetSkip(int64(page.Skip()))
405405
findOpts.Sort = page.Sort()
406406

407407
records := []*model.UserExample{}

internal/dao/userExample_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ func Test_userExampleDao_GetByColumns(t *testing.T) {
162162
d.SQLMock.ExpectQuery("SELECT .*").WillReturnRows(rows)
163163

164164
_, _, err := d.IDao.(UserExampleDao).GetByColumns(d.Ctx, &query.Params{
165-
Page: 0,
166-
Size: 10,
167-
Sort: "ignore count", // ignore test count(*)
165+
Page: 0,
166+
Limit: 10,
167+
Sort: "ignore count", // ignore test count(*)
168168
})
169169
if err != nil {
170170
t.Fatal(err)
@@ -177,8 +177,8 @@ func Test_userExampleDao_GetByColumns(t *testing.T) {
177177

178178
// err test
179179
_, _, err = d.IDao.(UserExampleDao).GetByColumns(d.Ctx, &query.Params{
180-
Page: 0,
181-
Size: 10,
180+
Page: 0,
181+
Limit: 10,
182182
Columns: []query.Column{
183183
{
184184
Name: "id",

0 commit comments

Comments
 (0)