-
Notifications
You must be signed in to change notification settings - Fork 3
/
go.json
465 lines (465 loc) · 15.7 KB
/
go.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
{
// snippet-variables: [snippet-variables](https://code.visualstudio.com/docs/editor/userdefinedsnippets)
// Place your snippets for go here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Print iris-admin request sturct": {
"prefix": "iris-adminreqs",
"body": [
"$1 string `json:\"$2\" form:\"$2\" uri:\"$2\" param:\"$2\"` // $3"
],
"description": "Print iris-admin request sturct"
},
"Print iris-admin source": {
"prefix": "iris-adminso",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"github.com/gookit/color\"",
" \"github.com/snowlyg/iris-admin/server/database\"",
" \"gorm.io/gorm\"",
")",
"var Source = new(source)",
"type source struct{}",
"func GetSources() []*$1 {",
" $2 := []*$1{",
" {",
" Base$1: Base$1{",
" $0",
" },",
" },",
" }",
" return $2",
"}",
"func (s *source) Init() error {",
" return database.Instance().Transaction(func(tx *gorm.DB) error {",
" if tx.Model(&$1{}).Where(\"id IN ?\",[]int{$3}).Find(&[]$1{}).RowsAffected == 1 {",
" color.Danger.Println(\"\\n[Mysql] --> $2 表的初始数据已存在!\")",
" return nil",
" }",
" if err := tx.Model(&$1{}).CreateInBatches(GetSources(),2).Error; err != nil {",
" return err",
" }",
" color.Info.Println(\"\\n[Mysql] --> $2 表初始数据成功!\")",
" return nil",
" })",
"}",
],
"description": "Print iris-admin source"
},
"Print iris-admin test main": {
"prefix": "iris-admintm",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"os\"",
" \"testing\"",
" \"strconv\"",
" \"github.com/snowlyg/httptest\"",
" \"github.com/snowlyg/iris-admin/server/web/common\"",
" \"github.com/snowlyg/helper/str\"",
" \"github.com/snowlyg/iris-admin/server/web/web_gin\"",
" \"github.com/snowlyg/iris-admin/server/cache\"",
")",
"var TestServer *web_gin.WebServer",
"var TestClient *httptest.Client",
"const Uri = \"/api/v1/$1/\"",
"func TestMain(m *testing.M) {",
" var uuid string",
" // xxxx.PartyFunc, xxxx.SeedFunc",
" uuid, TestServer = common.BeforeTestMainGin($2, $3)",
" $4",
" code := m.Run()",
" common.AfterTestMain(uuid, true)",
" cache.Remove()",
" $5",
" os.Exit(code)",
"}",
"func Create(client *httptest.Client, data map[string]interface{}) uint {",
" pageKeys := httptest.IdKeys()",
" client.POST(str.Join(Uri, \"create\"), httptest.NewResponses(http.StatusOK, response.ResponseOkMessage, pageKeys), httptest.NewWithJsonParamFunc(data))",
" return pageKeys.GetId()",
"}",
"func Delete(client *httptest.Client, id uint) {",
" client.DELETE(str.Join(Uri, \"delete/\", strconv.FormatUint(uint64(id), 10)), httptest.SuccessResponse)",
"}",
"func Detail(client *httptest.Client, id uint, detail httptest.Responses) {",
" client.GET(str.Join(Uri, \"detail/\", strconv.FormatUint(uint64(id), 10)), httptest.NewResponses(http.StatusOK, response.ResponseOkMessage, detail))",
"}",
],
"description": "Print iris-admin test main"
},
"Print iris-admin test func": {
"prefix": "iris-admintf",
"body": [
"// import rbac \"github.com/snowlyg/iris-admin-rbac/gin\"",
"func Test$1(t *testing.T) {",
" if TestServer == nil {",
" t.Error(\"test server is nil\")",
" return",
" }",
" TestClient = httptest.Instance(t, TestServer.GetEngine(), str.Join(\"http://\", web.CONFIG.System.Addr))",
" TestClient.Login(rbac.LoginUrl,\"\", httptest.NewResponses(http.StatusOK, response.ResponseOkMessage, rbac.LoginResponse))",
" if TestClient == nil {",
" t.Error(\"test client is nil\")",
" return",
" }",
" pageKeys := httptest.Responses{",
" {Key: \"pageSize\", Value: 20},",
" {Key: \"page\", Value: 1},",
" {Key: \"list\", Value: []httptest.Responses{",
" {",
" {Key: \"id\", Value: 1},",
" {Key: \"updatedAt\", Value: \"\", Type: \"notempty\"},",
" {Key: \"createdAt\", Value: \"\", Type: \"notempty\"},",
" },",
" }},",
" {Key: \"total\", Value: 0, Type: \"ge\"},",
" }",
" requestParams := map[string]interface{}{",
" \"page\": 1,",
" \"pageSize\": 20,",
" \"orderBy\": \"id\",",
" \"sort\": \"asc\",",
" }",
" TestClient.GET(str.Join(Uri, \"$2\"), httptest.NewResponses(http.StatusOK, response.ResponseOkMessage, pageKeys), httptest.NewWithQueryObjectParamFunc(requestParams))",
"}",
],
"description": "Print iris-admin test func"
},
"Print iris-admin test create func": {
"prefix": "iris-admintcf",
"body": [
"data := map[string]interface{}{",
" $1",
"}",
"id := Create(TestClient, data)",
"if id == 0 {",
" t.Error(\"create is failed\")",
" return",
"}",
"defer Delete(TestClient, id)",
],
"description": "Print iris-admin test create func"
},
"Print iris-admin controller resource function": {
"prefix": "iris-admincrf",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"// List list",
"func List(ctx *gin.Context) {",
" req := &ReqPaginate{}",
" if errs := ctx.ShouldBind(&req); errs != nil {",
" response.FailWithMessage(errs.Error(), ctx)",
" return",
" }",
" items := &PageResponse{}",
" var scopes []func(db *gorm.DB) *gorm.DB",
" total, err := items.Paginate(database.Instance(), req.PaginateScope(), scopes...)",
" if err != nil {",
" response.FailWithMessage(err.Error(), ctx)",
" return",
" }",
" response.OkWithData(response.PageResult{",
" List: items.Item,",
" Total: total,",
" Page: req.Page,",
" PageSize: req.PageSize,",
" }, ctx)",
"}",
"// Update update",
"func Update(ctx *gin.Context) {",
" var req request.IdBinding",
" if errs := ctx.ShouldBindUri(&req); errs != nil {",
" response.FailWithMessage(errs.Error(), ctx)",
" return",
" }",
" data := &Request{}",
" if errs := ctx.ShouldBindJSON(data); errs != nil {",
" response.FailWithMessage(errs.Error(), ctx)",
" return",
" }",
" item := new($1)",
" item.Base$1 = data.Base$1",
" err := item.Update(database.Instance(), scope.IdScope(req.Id))",
" if err != nil {",
" response.FailWithMessage(err.Error(), ctx)",
" return",
" }",
" response.Ok(ctx)",
"}",
"// Delete delete",
"func Delete(ctx *gin.Context) {",
" var reqId request.IdBinding",
" if errs := ctx.ShouldBindUri(&reqId); errs != nil {",
" response.FailWithMessage(errs.Error(), ctx)",
" return",
" }",
" item := new($1)",
" if err := item.Delete(database.Instance(), scope.IdScope(reqId.Id)); err != nil {",
" response.FailWithMessage(err.Error(), ctx)",
" return",
" }",
" response.Ok(ctx)",
"}",
"// Create create",
"func Create(ctx *gin.Context) {",
" req := &Request{}",
" if err := req.Request(ctx); err != nil {",
" response.FailWithMessage(err.Error(), ctx)",
" return",
" }",
" item := new($1)",
" item.Base$1 = req.Base$1",
" id, err := item.Create(database.Instance())",
" if err != nil {",
" response.FailWithMessage(err.Error(), ctx)",
" return",
" }",
" response.OkWithData(gin.H{",
" \"id\": id,",
" }, ctx)",
"}",
"// Detail detail",
"func Detail(ctx *gin.Context) {",
" var req request.IdBinding",
" if errs := ctx.ShouldBindUri(&req); errs != nil {",
" response.FailWithMessage(errs.Error(), ctx)",
" return",
" }",
" detail := &Response{}",
" err := detail.First(database.Instance(), scope.IdScope(req.Id))",
" if err != nil {",
" response.FailWithMessage(err.Error(), ctx)",
" return",
" }",
" response.OkWithData(detail, ctx)",
"}",
],
"description": "Print iris-admin controller resource function"
},
"Print iris-admin scope": {
"prefix": "iris-adminsc",
"body": [
"func $1Scope($2 $3) func(db *gorm.DB) *gorm.DB {",
" return func(db *gorm.DB) *gorm.DB {",
" return db.Where(\"$4 =?\", $2)",
" }",
"}",
],
"description": "Print iris-admin scope"
},
"Print iris-admin route group": {
"prefix": "iris-adminrg",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"github.com/gin-gonic/gin\"",
" \"github.com/snowlyg/iris-admin-rbac/gin/middleware\"",
")",
"func Group(app *gin.RouterGroup) {",
" router := app.Group(\"${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}\", middleware.Auth(), middleware.CasbinHandler(), middleware.OperationRecord())",
" {",
" router.GET(\"/list\", List)",
" router.POST(\"/create\", Create)",
" router.PUT(\"/update/:id\", Update)",
" router.GET(\"/detail/:id\", Detail)",
" router.DELETE(\"/delete/:id\", Delete)",
" }",
"}",
],
"description": "Print iris-admin route group"
},
"Print iris-admin migrate": {
"prefix": "iris-adminmig",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"github.com/go-gormigrate/gormigrate/v2\"",
" \"gorm.io/gorm\"",
")",
"func GetMigration() *gormigrate.Migration {",
" return &gormigrate.Migration{",
" // 20230314170919_create_xxxx_table",
" ID: \"$CURRENT_YEAR$CURRENT_MONTH$CURRENT_DATE$CURRENT_HOUR$CURRENT_MINUTE$CURRENT_SECOND$1_table\",",
" Migrate: func(tx *gorm.DB) error {",
" return tx.AutoMigrate(&$3{})",
" },",
" Rollback: func(tx *gorm.DB) error {",
" return tx.Migrator().DropTable(\"$2\")",
" },",
" }",
"}"
],
"description": "Print iris-admin route migrate"
},
"Print iris-admin model": {
"prefix": "iris-adminm",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"time\"",
" \"gorm.io/gorm\"",
" \"github.com/snowlyg/iris-admin/server/zap_server\"",
")",
"// gorm:\"column:xxxx_xxxx\" json:\"xxxx_xxxx\" form:\"xxxx_xxxx\" uri:\"xxxx_xxxx\" param:\"xxxx_xxxx\"",
"type $1 struct {",
" gorm.Model",
" Base$1",
"}",
"type Base$1 struct {",
" $2",
"}",
"func (item *$1) mc() map[string]interface{} {",
" return map[string]interface{}{",
" $2",
" }",
"}",
"// Create create",
"func (item *$1) Create(db *gorm.DB) (uint, error) {",
" if db == nil {",
" return 0, gorm.ErrInvalidDB",
" }",
" err := db.Model(&$1{}).Create(item).Error",
" if err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return 0, err",
" }",
" return item.ID, nil",
"}",
"// Update update",
"func (item *$1) Update(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error {",
" if db == nil {",
" return gorm.ErrInvalidDB",
" }",
" err := db.Model(&$1{}).Scopes(scopes...).Updates(item.mc()).Error",
" if err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return err",
" }",
" return nil",
"}",
"// Delete delete",
"func (item *$1) Delete(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error {",
" if db == nil {",
" return gorm.ErrInvalidDB",
" }",
" err := db.Unscoped().Scopes(scopes...).Delete(item).Error",
" if err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return err",
" }",
" return nil",
"}",
],
"description": "Print iris-admin model"
},
"Print iris-admin request": {
"prefix": "iris-adminreq",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"github.com/gin-gonic/gin\"",
" \"github.com/snowlyg/iris-admin/server/database/orm\"",
" \"github.com/snowlyg/iris-admin/server/zap_server\"",
")",
"type Request struct {",
" Base$1",
"}",
"func (req *Request) Request(ctx *gin.Context) error {",
" if err := ctx.ShouldBindJSON(req); err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return orm.ErrParamValidate",
" }",
" return nil",
"}",
"type ReqPaginate struct {",
" orm.Paginate",
" $2",
"}"
],
"description": "Print iris-admin request"
},
"Print iris-admin response": {
"prefix": "iris-adminres",
"body": [
"package ${TM_DIRECTORY/^.+[\\/\\\\]+(.*)$/$1/}",
"import (",
" \"github.com/gin-gonic/gin\"",
" \"github.com/snowlyg/iris-admin/server/database/orm\"",
" \"github.com/snowlyg/iris-admin/server/zap_server\"",
")",
"type Response struct {",
" orm.Model",
" Base$1",
"}",
"func (res *Response) First(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error {",
" if db == nil {",
" return gorm.ErrInvalidDB",
" }",
" db = db.Model(&$1{})",
" if len(scopes) > 0 {",
" db.Scopes(scopes...)",
" }",
" err := db.First(res).Error",
" if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {",
" zap_server.ZAPLOG.Error(err.Error())",
" return err",
" }",
" return nil",
"}",
"// Paginate",
"type PageResponse struct {",
" Item []*Response",
"}",
"func (res *PageResponse) Paginate(db *gorm.DB, pageScope func(db *gorm.DB) *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) (int64, error) {",
" if db == nil {",
" return 0,gorm.ErrInvalidDB",
" }",
" db = db.Model(&$1{})",
" if len(scopes) > 0 {",
" db.Scopes(scopes...)",
" }",
" var count int64",
" err := db.Count(&count).Error",
" if err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return 0, err",
" }",
" db.Scopes(pageScope)",
" err = db.Find(&res.Item).Error",
" if err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return 0, err",
" }",
" return count, nil",
"}",
"func (res *PageResponse) Find(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error {",
" if db == nil {",
" return gorm.ErrInvalidDB",
" }",
" db = db.Model(&$1{})",
" if len(scopes) > 0 {",
" db.Scopes(scopes...)",
" }",
" err := db.Find(&res.Item).Error",
" if err != nil {",
" zap_server.ZAPLOG.Error(err.Error())",
" return err",
" }",
" return nil",
"}",
],
"description": "Print iris-admin response"
},
}