-
Notifications
You must be signed in to change notification settings - Fork 161
/
page.yaml
3263 lines (3124 loc) · 175 KB
/
page.yaml
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
header: |
<h1 align="center">🦩 Go Recipes</h1>
<p align="center">Handy well-known and <i>lesser</i>-known tools for Go projects</p>
> _Know some cool tool or one-liner? Have a feature request or an idea?_
> _Feel free to edit this page or create an Issue!_
[![Hits](https://hits.sh/github.com/nikolaydubina/go-recipes.svg?view=today-total&extraCount=64309)](https://hits.sh/github.com/nikolaydubina/go-recipes/)
[![go-recipes](https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true)](https://github.com/nikolaydubina/go-recipes)
contents:
title: Contents
entry:
back: ⏫
requirements:
title: Requirements
example:
title: Example
groups:
- title: AI Tools
entries:
- title: Advanced autocompletion
name: Copilot
description: Start typing and after few seconds you will get autocompletion suggestion. Some useful ways to interact with it listed below.
url: https://marketplace.visualstudio.com/items?itemName=GitHub.copilot
example_image_url: https://user-images.githubusercontent.com/37570492/212964557-8d832278-61bb-4288-a8a7-47f35859e868.gif
commands:
- given a function signature and docstring, it will suggest function body
- given a function body, it will suggest docstring
requirements:
- VSCode
- GitHub account
- title: Code analysis and recommendations
name: charmbracelet/mods
description: This is a nice looking CLI wrapper for major LLM APIs from [Charm](https://github.com/charmbracelet) team. It supports OpenAI and [LocalAI](https://github.com/go-skynet/LocalAI). It passes arbitrary human language command string and concatenated with STDIN input. Multiple useful commands are possible.
url: https://github.com/charmbracelet/mods
commands:
- mods -f "what are your thoughts on improving this code?" < main.go | glow
- mods -f "you are an expert Go programmer. find potential bugs in following Go code." < my_class.go | glow
example_image_url: https://user-images.githubusercontent.com/25087/237975943-738fe969-1c9f-4849-af8a-cde38156ce92.gif
requirements:
- "# OpenAI token or LocalAI model and server"
- go install github.com/charmbracelet/glow@latest
- go install github.com/charmbracelet/mods@latest
- title: Pull request recommendations
name: gpt-pullrequest-updater
description: This tool generates GitHub pull request description and review using OpenAI ChatGPT. There is also GitHub Action available.
url: https://github.com/ravilushqa/gpt-pullrequest-updater
author: https://github.com/ravilushqa
example_image_url: ./img/gpt-pullrequest-updater-example.png
requirements:
- "# OpenAI token"
- "# GitHub token"
- go install github.com/ravilushqa/gpt-pullrequest-updater/cmd/description@latest
- go install github.com/ravilushqa/gpt-pullrequest-updater/cmd/review@latest
- title: Commit message recommendation
description: Short summaries of changes usually work well.
name: charmbracelet/mods
url: https://github.com/charmbracelet/mods
commands:
- git diff | mods "summarize following git diff into short git commit message."
- git diff | mods "you are expert Go programmer. you are owner of this codebase. think through step by step. summarize following git diff into short git commit message under 10 words."
example_output: |
Add new entries for Using AI in Go projects, including Advanced autocompletion with Copilot and Code analysis and recommendations with charmbracelet/mod. Update page.yaml accordingly.
requirements:
- "# OpenAI token or LocalAI model and server"
- go install github.com/charmbracelet/mods@latest
- title: Test case recommendation
name: charmbracelet/mods
url: https://github.com/charmbracelet/mods
description: Concatenate two files and ask to recommend missing test cases. It is not precise, has high false positive and high false negative rate. Often can not detect that tests cases are present at all. However, it can give a fresh perspective on your code. Best results are produced when asking succinct short replies. Example outputs below.
commands:
- cat fpdecimal.go fpdecimal_test.go | head -c 3600 | mods -f "you are an expert Go programmer. investigate supplied Go program and associated test suite. think through this step by step. make sure you get the right answer. recommend missing test cases. write very succinctly. under 100 words." | glow
- cat fpdecimal.go fpdecimal_test.go | head -c 4000 | mods -f "investigate supplied Go program and associated test suite. recommend missing test cases." | glow
example_output: |
For additional test cases, consider adding tests for negative float values, positive and negative infinity, unsigned
integers, zero divided by a number greater than zero, and division with only zeros.
------------------
Test cases:
• Test for unmarshalling JSON into Decimal
• Test for marshalling Decimal to JSON
• Test for multiplication with zero
• Test for multiplication identity
• Test for division with zero
• Test for all comparison operations for the Decimal struct.
------------------
Missing test cases for the fpdecimal Go program include those for testing the DivMod and FromString functions.
Additionally, there should be tests checking that zero division is not allowed, and tests that ensure the
FractionDigits value does not change during the program's runtime. Important test cases include comparing decimals
for equality, as well as testing the commutativity, associativity, and identity properties of addition and
multiplication. Finally, the program should have a test that verifies the MarshalJSON and UnmarshalJSON
functions.
- title: Time complexity estimate
name: charmbracelet/mods
url: https://github.com/charmbracelet/mods
description: This is one of recommended use cases by OpenAI website. It can produce fairly good estimations. However, in its direct form usefulness is questionable, since complex cases are not handled precisely enough, educational potential is limited, and simple cases do not require this. Perhaps, this will be utilized in future work on using models in compiler and programming. Copy function and pipe it to model with prompt asking for time complexity estimation. Below is an example.
commands:
- pbpaste | mods -f "calculate time complexity of following Go code function." | glow
example_content_ext: go
example_content: |
func AppendFixedPointDecimal(b []byte, v int64, p int) []byte {
if v == 0 {
return append(b, '0')
}
if p == 0 {
return strconv.AppendInt(b, v, 10)
}
if v < 0 {
v = -v
b = append(b, '-')
}
s := len(b)
b = strconv.AppendInt(b, v, 10)
if len(b)-s > p {
i := len(b) - p
b = append(b, 0)
copy(b[i+1:], b[i:])
b[i] = '.'
} else {
i := 2 + p - (len(b) - s)
for j := 0; j < i; j++ {
b = append(b, 0)
}
copy(b[s+i:], b[s:])
copy(b[s:], []byte(zeroPrefix[:i]))
}
return b
}
example_output: |
The time complexity of the AppendFixedPointDecimal function is O(N), where N is the length of the input byte slice
b. This is because the function performs a constant number of operations for each byte in b, and the largest
operation within the function is the loop that appends zeros to the byte slice, which has a length proportional to
the input. Other operations, such as integer conversions and comparisons, are considered constant time since the
input size is fixed.
------------------
The time complexity of the function depends on the input values v and p .
• The first three if statements before the main computation take constant time,
so they don't contribute to the overall time complexity.
• The strconv.AppendInt function used twice has a time complexity of
O(log(v)), where v is the integer being converted to a string representation in
base 10.
• The condition len(b)-s > p has a constant time complexity.
• The append and copy operations inside the if and else blocks take linear
time proportional to p .
• The for loop has a constant number of iterations, specifically 2 + p - (
len(b)-s ). The append and copy operations inside the loop also take linear
time proportional to p .
Therefore, the overall time complexity of the function is O(log(v) + p).
- title: Test
entries:
- title: ":fire: Continuous Tests Monitoring"
description: Track tests duration, errors, flackiness. Run JUnit test output converter and submit result to codecov.io via GitHub Action.
name: codecov.io
url: https://app.codecov.io
author: https://codecov.io
example_image_url: ./img/codecov-tests.png
requirements:
- go install gotest.tools/gotestsum@latest
commands:
- go test -coverprofile=coverage.out -cover -json ./... | gotestsum --junitfile tests.xml
- title: Make treemap of coverage
description: Visualize distribution of code coverage in your project. This helps to identify code areas with high and low coverage. Useful when you have large project with lots of files and packages. This 2D "image-hash" of your project should be more representative than a single number. Also available at https://go-cover-treemap.io.
example_image_url: ./img/hugo-code-coverage.svg
name: go-cover-treemap
url: https://github.com/nikolaydubina/go-cover-treemap
author: https://github.com/nikolaydubina
requirements:
- go install github.com/nikolaydubina/go-cover-treemap@latest
commands:
- go test -coverprofile cover.out ./...
- go-cover-treemap -coverprofile cover.out > out.svg
- title: Browse coverage
description: This is very helpful tool from the official Go toolchain. Similar visualization is integrated into VSCode and Goland, but can be used separately.
example_image_url: ./img/tool-cover-html.png
commands:
- go test -coverprofile cover.out ./...
- go tool cover -html=cover.out
- title: Browse coverage
name: gocov-html
url: https://github.com/matm/gocov-html
author: https://github.com/matm
description: Browse code coverage in statically generated HTML page. Multiple styles are supported. You may need to convert coverage report into `gocov` format.
example_image_url: ./img/gocov-html.png
commands:
- gocov test strings | gocov-html -t golang > strings.html
- gocov test encoding/csv strings | gocov-html -t kit > strings.html
- "gocov test strings|./gocov-html -cmax 90 > strings.html # show functions with <90% coverage"
requirements:
- go install github.com/axw/gocov/gocov@latest
- go install github.com/matm/gocov-html/cmd/gocov-html@latest
- title: ":fire: Browse coverage"
name: xgo
description: "The displayed coverage is a combination of coverage and git diff. By default, only modified lines were shown. This helps to quickly locate changes that were not covered, and add tests for them incrementally."
url: https://github.com/xhd2015/xgo
author: https://github.com/xhd2015
example_image_url: https://github.com/xhd2015/xgo/raw/master/doc/img/coverage.jpg
commands:
- xgo tool coverage serve cover.out
requirements:
- go install github.com/xhd2015/xgo/cmd/xgo@latest
- title: Browse coverage in terminal
description: Browse code coverage similarly to HTML provided by official Go toolchain, but in terminal. Other notable features are package level statistics, coverage only for changed files.
name: gocovsh
url: https://github.com/orlangure/gocovsh
author: https://github.com/orlangure
example_image_url: https://github.com/orlangure/gocovsh/raw/master/examples/general.gif
commands:
- go test -cover -coverprofile coverage.out
- "gocovsh # show all files from coverage report"
- "git diff --name-only | gocovsh # only show changed files"
- "git diff | gocovsh # show coverage on top of current diff"
- "gocovsh --profile profile.out # for other coverage profile names"
requirements:
- go install github.com/orlangure/gocovsh@latest
- title: Pretty print coverage in terminal
description: It is similar to `go tool cover -html=cover.out` but in terminal. You can filter by functions, packages, minimum coverage, and more.
name: nikandfor/cover
url: https://github.com/nikandfor/cover
author: https://github.com/nikandfor
commands:
- cover
requirements:
- go install github.com/nikandfor/cover@latest
example_image_url: img/cover.png
- title: Run coverage collector server
description: This tool allows to collect coverage as soon as code is executed.
url: https://github.com/qiniu/goc
author: https://github.com/qiniu
example_image_url: https://github.com/qiniu/goc/raw/master/docs/images/intro.gif
name: goc
commands:
- goc server
- goc build
- goc profile
requirements:
- go install github.com/qiniu/goc@latest
- title: Visualize live coverage in VSCode
description: Official Go VSCode plugin already has coverage highlighting. In addition to that, this tool shows covered lines as soon as they are executed. This can be useful for running manual integration or system tests or debugging.
url: https://github.com/qiniu/goc
author: https://github.com/qiniu
example_image_url: https://github.com/qiniu/goc/raw/master/docs/images/goc-vscode.gif
name: goc
requirements:
- go install github.com/qiniu/goc@latest
- title: ":fire: Detect drops in coverage"
name: go-test-coverage
description: This tool designed to report issues when test coverage falls below a specified threshold. Likely you would want to use it in the CI.
url: https://github.com/vladopajic/go-test-coverage
author: https://github.com/vladopajic
requirements:
- go install github.com/vladopajic/go-test-coverage/v2@latest
commands:
- go-test-coverage --config=./.testcoverage.yml
- title: Shuffle tests
description: This is less known option that is disabled by default. However, for robust test suite it is beneficial. More test flags and full description is available at `go help testflag`.
commands:
- go test -shuffle=on
- title: Run tests sequentially
description: Use when you need to synchronize tests, for example in integration tests that share environment. [Official documentation](https://pkg.go.dev/cmd/go#hdr-Testing_flags).
commands:
- go test -p 1 -parallel 1 ./...
- title: Run tests in parallel
description: Add `t.Parallel` to your tests case function bodies. As per documentation, by default `-p=GOMAXPROCS` and `-parallel=GOMAXPROCS` when you run `go test`. Different packages by default run in parallel, and tests within package can be enforced to run in parallel too. Make sure to copy test case data to new variable, why explained [here](https://gist.github.com/posener/92a55c4cd441fc5e5e85f27bca008721). [Official documentation](https://pkg.go.dev/cmd/go#hdr-Testing_flags).
example_content_ext: go
example_content: |
...
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
...
- title: Run all Fuzz tests
description: Standard tool runs only single fuzz test. Use following to run all fuzz tests in a package.
commands:
- go test -list . | grep Fuzz | xargs -P 8 -I {} go test -fuzz {} -fuzztime 5s .
- title: Detect goroutine leaks
description: Instrument your test cases with verification call. Alternatively, you can add single call in `TestMain`. This tool was recommended by Pyroscope in [blog](https://grafana.com/blog/2023/04/19/how-to-troubleshoot-memory-leaks-in-go-with-grafana-pyroscope/).
url: https://github.com/uber-go/goleak
author: Uber
name: goleak
example_content_ext: go
example_content: |
func TestA(t *testing.T) {
defer goleak.VerifyNone(t)
...
}
requirements:
- go get -u go.uber.org/goleak
- title: "Detect goroutine leaks"
description: Refactored, tested variant of the goroutine leak detector found in both `net/http` tests and the cockroachdb source tree. You have to call this library in your tests.
name: leaktest
url: https://github.com/fortytw2/leaktest
author: https://github.com/fortytw2
example_content: |
func TestPoolContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
defer leaktest.CheckContext(ctx, t)()
go func() {
for {
time.Sleep(time.Second)
}
}()
}
- title: ":fire: Visualize test runs"
description: This tool visualizes Go test results in a browser. It's helpful with understanding parallelism of tests and identifying slow tests. More information can be found in our blog post about optimizing Go tests parallelism.
name: vgt
url: https://github.com/roblaszczak/vgt
author: https://github.com/roblaszczak
example_image_url: https://github.com/roblaszczak/vgt/raw/main/docs/img3.png
commands:
- go test -json ./... | vgt
requirements:
- go install github.com/roblaszczak/vgt@latest
- title: Summarize `go test`
description: This lightweight wrapper around STDOUT of JSON of `go test` will nicely render colorized test status, details of failures, duration, coverage, and package summary.
name: tparse
url: https://github.com/mfridman/tparse
author: https://github.com/mfridman
example_image_url: ./img/tparse.png
commands:
- set -o pipefail && go test ./... -json | tparse -all
requirements:
- go install github.com/mfridman/tparse@latest
- title: Decorate `go test`
description: Add colors and enrich `go test` output. It can be used in CI pipeline and has lots of alternative visualizations and options.
name: richgo
url: https://github.com/kyoh86/richgo
author: https://github.com/kyoh86
commands:
- richgo test ./...
example_image_url: https://asciinema.org/a/99810.png
requirements:
- go install github.com/kyoh86/richgo@latest
- title: "Decorate `go test`"
description: Add colors to `go test` output. Very lightweight wrapper around `go test` STDOUT.
name: gotest
url: https://github.com/rakyll/gotest
author: https://github.com/rakyll
example_image_url: https://raw.githubusercontent.com/jonasbn/go-test-demo/1.0.0/gotest-go-test-demo.png
commands:
- gotest ./...
requirements:
- go install github.com/rakyll/gotest@latest
- title: Decorate `go test`
description: This wrapper around `go test` renders test output in easy to read format. Also supports JUnit, JSON output, skipping slow tests, running custom binary.
name: gotestsum
url: https://github.com/gotestyourself/gotestsum
author: https://github.com/dnephin
commands:
- gotestsum --format dots
example_image_url: https://user-images.githubusercontent.com/442180/182284939-e08a0aa5-4504-4e30-9e88-207ef47f4537.gif
requirements:
- go install gotest.tools/gotestsum@latest
- title: Format `go test` results as documentation
name: gotestdox
description: Decorates `go test` results by converting CamelCaseTestNames into readable sentences.
url: https://github.com/bitfield/gotestdox
author: https://github.com/bitfield
example_image_url: https://github.com/bitfield/gotestdox/raw/main/img/demo.gif
commands:
- gotestdox ./...
requirements:
- go install github.com/bitfield/gotestdox/cmd/gotestdox@latest
- title: Get slowest tests
description: This is subcommand of `gotestsum` that processes JSON output of `go test` to find slowest tests.
name: gotestsum
url: https://github.com/gotestyourself/gotestsum
author: https://github.com/dnephin
commands:
- go test -json -short ./... | gotestsum tool slowest --threshold 500ms
example_output: |
gotest.tools/example TestSomething 1.34s
gotest.tools/example TestSomethingElse 810ms
requirements:
- go install gotest.tools/gotestsum@latest
- title: Auto-Instrument skipping slowest tests
description: This is subcommand of `gotestsum` that processes JSON output of `go test` to find slowest tests and instruments test cases to skip them with `t.Skip()` statements.
name: gotestsum
url: https://github.com/gotestyourself/gotestsum
author: https://github.com/dnephin
commands:
- go test -json ./... | gotestsum tool slowest --skip-stmt "testing.Short" --threshold 200ms
example_output: |
gotest.tools/example TestSomething 1.34s
gotest.tools/example TestSomethingElse 810ms
requirements:
- go install gotest.tools/gotestsum@latest
- title: Automatically re-run failed tests
description: Other useful option of `gotestsum` is to re-run failed tests. For example, if you have flaky tests that are idempotent, then re-running them may be a quick fix.
name: gotestsum
url: https://github.com/gotestyourself/gotestsum
author: https://github.com/dnephin
commands:
- gotestsum --rerun-fails --packages="./..."
requirements:
- go install gotest.tools/gotestsum@latest
- title: Make `JSUnit` test report
description: JUnit is widely used format for test reporting.
name: gotestsum
url: https://github.com/gotestyourself/gotestsum
author: https://github.com/dnephin
commands:
- go test -json ./... | gotestsum --junitfile unit-tests.xml
requirements:
- go install gotest.tools/gotestsum@latest
- title: "Make `JSUnit` test report"
description: JUnit is widely used format for test reporting. Go benchmark output is also supported.
url: https://github.com/jstemmer/go-junit-report
name: go-junit-report
author: https://github.com/jstemmer
commands:
- go test -v 2>&1 ./... | go-junit-report -set-exit-code > report.xml
requirements:
- go install github.com/jstemmer/go-junit-report/v2@latest
- title: Get packages without tests
description: If code coverage does not report packages without tests. For example for CI or quality control.
requirements:
- https://stedolan.github.io/jq/download/
commands:
- go list -json ./... | jq -rc 'select((.TestGoFiles | length)==0) | .ImportPath'
example_output: |
github.com/gin-gonic/gin/ginS
github.com/gin-gonic/gin/internal/json
- title: Perform Mutation Testing
description: Mutation testing is a technique used to assess the quality and coverage of test suites. It involves introducing controlled changes to the code base, simulating common programming mistakes. These changes are, then, put to test against the test suites. A failing test suite is a good sign. It indicates that the tests are identifying mutations in the code—it "killed the mutant". If all tests pass, we have a surviving mutant. This highlights an area with weak coverage. It is an opportunity for improvement.
url: https://github.com/gtramontina/ooze
name: ooze
author: https://github.com/gtramontina
requirements:
- go get github.com/gtramontina/ooze
commands:
- go test -v -tags=mutation
example_image_url: https://github.com/gtramontina/ooze/blob/main/.assets/report.png
- title: "Perform Mutation Testing"
description: This is fork of [zimmski/go-mutesting](https://github.com/zimmski/go-mutesting). It has more mutators and latest updates.
name: "avito-tech/go-mutesting"
url: https://github.com/avito-tech/go-mutesting
author: https://github.com/vasiliyyudin
requirements:
- go install github.com/avito-tech/go-mutesting/cmd/go-mutesting@latest
commands:
- go-mutesting ./...
example_content_ext: go
example_content: |
for _, d := range opts.Mutator.DisableMutators {
pattern := strings.HasSuffix(d, "*")
- if (pattern && strings.HasPrefix(name, d[:len(d)-2])) || (!pattern && name == d) {
+ if (pattern && strings.HasPrefix(name, d[:len(d)-2])) || false {
continue MUTATOR
}
}
- title: "Perform Mutation Testing"
description: Find common bugs source code that would pass tests. This is earliest tool for mutation testing in Go. More functions and permutations were added in other mutation Go tools it inspired.
name: go-mutesting
url: https://github.com/zimmski/go-mutesting
author: https://github.com/zimmski
requirements:
- go install github.com/zimmski/go-mutesting/cmd/go-mutesting@latest
commands:
- go-mutesting ./...
example_content_ext: go
example_content: |
for _, d := range opts.Mutator.DisableMutators {
pattern := strings.HasSuffix(d, "*")
- if (pattern && strings.HasPrefix(name, d[:len(d)-2])) || (!pattern && name == d) {
+ if (pattern && strings.HasPrefix(name, d[:len(d)-2])) || false {
continue MUTATOR
}
}
- title: "Trace tests"
description: Collect test execution as distributed traces. This is useful for tracking test duration, failures, flakiness. You distributed tracing storage, search, UI, exploration, dashboards, alarms — all will automatically become test status collection. If you run integration tests in your CI, then it is particularly handy to investigate your integration tests same way as real requests, such as Go processes, databases, etc. However, if you do not have distributed traces, it is still useful for adhoc investigations. This tool processes STDOUT of `go test`. No automatic instrumentation is done.
name: go-test-trace
url: https://github.com/rakyll/go-test-trace
author: https://github.com/rakyll
example_image_url: https://i.imgur.com/E18PYk4.png
commands:
- go-test-trace ./...
requirements:
- "# open telemetry collector"
- "# traces UI (Datadog, Jaeger, Honeycomb, NewRelic)"
- go install github.com/rakyll/go-test-trace@latest
- title: Speedup tests for large codebases
description: As of 2023-12-11, large codebases may be slow to run tests by default commands. Compiling package test binaries first and executing them later can lead to significant overall speedup.
commands:
- go test -c ./pkg/mypackage -o my_pkg_test_binary.bin
- "./my_pkg_test_binary.bin | ... # normal test output post processing"
- title: Dependencies
entries:
- title: Get Go version of current module
description: For example, setup correct Go version automatically from `go.mod` in CI.
requirements:
- https://stedolan.github.io/jq/download/
commands:
- go mod edit -json | jq -r .Go
example-output: 1.16
- title: Get Go versions of upstream modules
description: Use this when upgrading version of Go or finding old modules.
requirements:
- https://stedolan.github.io/jq/download/
commands:
- go list -deps -json ./... | jq -rc 'select(.Standard!=true and .Module.GoVersion!=null) | [.Module.GoVersion,.Module.Path] | join(" ")' | sort -V | uniq
example_output: |
1.11 github.com/ugorji/go/codec
1.11 golang.org/x/crypto
1.12 github.com/golang/protobuf
- title: Get directly dependent modules that can be upgraded
description: Keep your modules updated. Similar function is integrated in VSCode official Go plugin and GoLand.
commands:
- go list -u -m $(go list -m -f '{{.Indirect}} {{.}}' all | grep '^false' | cut -d ' ' -f2) | grep '\['
example_output: |
github.com/goccy/go-json v0.5.1 [v0.7.3]
github.com/golang/protobuf v1.3.3 [v1.5.2]
github.com/json-iterator/go v1.1.9 [v1.1.11]
- title: Get upstream modules without Go version
description: Find outdated modules or imports that you need to upgrade.
commands:
- go list -deps -json ./... | jq -rc 'select(.Standard!=true and .Module.GoVersion==null) | .Module.Path' | sort -u
requirements:
- https://stedolan.github.io/jq/download/
example_output: |
github.com/facebookgo/clock
golang.org/x/text
gopkg.in/yaml.v2
- title: Get available module versions
description: This works even if you did not download or install module locally. This is useful to check to which version you can upgrade to, what is the latest version, and whether there are v2+ major versions recognized by Go toolchain.
commands:
- go list -m -versions github.com/google/gofuzz
example-output: github.com/google/gofuzz v1.0.0 v1.1.0 v1.2.0
- title: ":fire: Get go module libyear, number of releases, version delta"
description: "[libyear](https://libyear.com) is a simple measure of software dependency freshness. It is a single number telling you how up-to-date your dependencies are. For example Rails 5.0.0 (June 2016) is 1 libyear behind 5.1.2 (June 2017). This tool can also compute number of releases, and version number delta."
name: go-libyear
url: https://github.com/nieomylnieja/go-libyear
author: https://github.com/nieomylnieja
commands:
- go-libyear /path/to/go.mod
example_output: |
package version date latest latest_date libyear
github.com/nieomylnieja/go-libyear 2023-11-06 2.41
github.com/pkg/errors v0.8.1 2019-01-03 v0.9.1 2020-01-14 1.03
github.com/urfave/cli/v2 v2.20.0 2022-10-14 v2.25.7 2023-06-14 0.67
golang.org/x/mod v0.12.0 2023-06-21 v0.14.0 2023-10-25 0.35
golang.org/x/sync v0.3.0 2023-06-01 v0.5.0 2023-10-11 0.36
requirements:
- go install github.com/nieomylnieja/go-libyear/cmd/go-libyear@latest
- title: Make graph of upstream modules
description: For each module, the node representing the greatest version (i.e., the version chosen by Go's minimal version selection algorithm) is colored green. Other nodes, which aren't in the final build list, are colored grey.
name: modgraphviz
url: https://golang.org/x/exp/cmd/modgraphviz
author: official Go team
commands:
- go mod graph | modgraphviz | dot -Tsvg -o mod-graph.svg
example_image_url: ./img/modgraphviz-go-featureprocessing.svg
requirements:
- https://graphviz.org/download/
- go install golang.org/x/exp/cmd/modgraphviz@latest
- title: "Make graph of upstream packages"
description: Find unexpected dependencies or visualize project. Works best for small number of packages, for large projects use `grep` to narrow down subgraph. Without `-deps` only for current module.
commands:
- "go list -deps -json ./... | jq -c 'select(.Standard!=true) | {from: .ImportPath, to: .Imports[]}' | jsonl-graph | dot -Tsvg > package-graph.svg"
example_image_url: ./img/packages-graph.svg
name: import-graph
url: https://github.com/nikolaydubina/import-graph
author: https://github.com/nikolaydubina
requirements:
- https://stedolan.github.io/jq/download/
- https://graphviz.org/download/
- go install github.com/nikolaydubina/import-graph@latest
- go install github.com/nikolaydubina/jsonl-graph@latest
- title: "Scrape details about upstream modules and make graph"
description: Find low quality or unmaintained dependencies.
commands:
- go mod graph | import-graph -i=gomod | jsonl-graph -color-scheme=file://$PWD/basic.json | dot -Tsvg > output.svg
example_image_url: ./img/gin-mod-graph-collected.svg
name: import-graph
url: https://github.com/nikolaydubina/import-graph
author: https://github.com/nikolaydubina
requirements:
- https://graphviz.org/download/
- go install github.com/nikolaydubina/import-graph@latest
- go install github.com/nikolaydubina/jsonl-graph@latest
- title: Scrape licenses of upstream dependencies
description: Collect all the licenses for checking if you can use the project, for example in proprietary or commercial environment.
name: go-licenses
url: https://github.com/google/go-licenses
author: Google
example_output: |
github.com/cli/safeexec,https://github.com/cli/safeexec/blob/master/LICENSE,BSD-2-Clause
github.com/bep/tmc,https://github.com/bep/tmc/blob/master/LICENSE,MIT
github.com/aws/aws-sdk-go,https://github.com/aws/aws-sdk-go/blob/master/LICENSE.txt,Apache-2.0
github.com/jmespath/go-jmespath,https://github.com/jmespath/go-jmespath/blob/master/LICENSE,Apache-2.0
github.com/gorilla/websocket,https://github.com/gorilla/websocket/blob/master/LICENSE,BSD-2-Clause
github.com/pelletier/go-toml/v2,https://github.com/pelletier/go-toml/blob/master/v2/LICENSE,MIT
github.com/spf13/cobra,https://github.com/spf13/cobra/blob/master/LICENSE.txt,Apache-2.0
github.com/kyokomi/emoji/v2,https://github.com/kyokomi/emoji/blob/master/v2/LICENSE,MIT
go.opencensus.io,Unknown,Apache-2.0
github.com/Azure/azure-storage-blob-go/azblob,https://github.com/Azure/azure-storage-blob-go/blob/master/azblob/LICENSE,MIT
github.com/yuin/goldmark-highlighting,https://github.com/yuin/goldmark-highlighting/blob/master/LICENSE,MIT
commands:
- go-licenses csv github.com/gohugoio/hugo
requirements:
- go install github.com/google/go-licenses@latest
- title: Explore dependencies
description: This tool has extensive syntax for filtering dependencies graphs. It can work with packages and modules.
name: goda
url: https://github.com/loov/goda
author: "[Egon Elbre]([email protected])"
commands:
- goda graph . | dot -Tsvg -o graph.svg
- goda graph -cluster -short "github.com/nikolaydubina/go-cover-treemap:all" | dot -Tsvg -o graph.svg
requirements:
- https://graphviz.org/download/
- go install github.com/loov/goda@latest
example_image_url: https://github.com/loov/goda/raw/master/graph.svg
- title: Explore dependencies interactively
description: Useful in large refactorings, dependency breaking, physical layout changes.
name: spaghetti
url: https://github.com/adonovan/spaghetti
author: "[Alan Donovan](https://github.com/adonovan), official Go team"
example_image_url: https://github.com/adonovan/spaghetti/blob/main/screenshot.png
requirements:
- go install github.com/adonovan/spaghetti@latest
- title: ":fire: Explore dependencies graph interactively"
description: Transform your Go project's dependency graph into a dynamic, interactive visualization with modview. This powerful tool takes the complexity out of your module graph, offering a clear and explorable view of your project's dependencies.
name: modview
url: https://github.com/bayraktugrul/modview
author: https://github.com/bayraktugrul
example_image_url: https://github.com/bayraktugrul/modview/raw/main/modview-opt.gif
commands:
- modview --open
requirements:
- go install github.com/bayraktugrul/modview@latest
- title: ":fire: Enforce Go code architecture"
description: "Architecture linter. Will check all project import path and compare with arch rules defined in yml file. Useful for hexagonal / onion / ddd / mvc / etc patterns."
name: go-arch-lint
url: https://github.com/fe3dback/go-arch-lint
author: https://github.com/fe3dback
example_image_url: https://github.com/fe3dback/go-arch-lint/blob/master/docs/images/check-example.png
requirements:
- go install github.com/fe3dback/go-arch-lint@latest
commands:
- go-arch-lint
- title: ":fire: Check Clean Architecture"
description: Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.
author: https://github.com/roblaszczak
url: https://github.com/roblaszczak/go-cleanarch
name: go-cleanarch
commands:
- go-cleanarch
requirements:
- go install github.com/roblaszczak/go-cleanarch@latest
- title: Use `go mod` directives
description: Tell Go compiler which versions of upstreams to include in your build. Tell all users of your module how to deal with versions of your module.
example_content: |
// Deprecated: use example.com/mod/v2 instead.
module example.com/mod
go 1.16
require example.com/other/thing v1.0.2
require example.com/new/thing/v2 v2.3.4
exclude example.com/old/thing v1.2.3
replace example.com/bad/thing v1.4.5 => example.com/good/thing v1.4.5
retract [v1.9.0, v1.9.5]
- title: ":fire: Locally patch dependency"
name: "`replace`"
description: "This can be useful for development. First appeared on [blog](https://eli.thegreenplace.net/2024/locally-patching-dependencies-in-go)."
commands:
- "# clone your dependency to $DEP folder"
- "# make changes"
- go mod edit -replace github.com/google/go-cmp=$DEP
- title: ":fire: Locally patch dependency"
name: "`go.work`"
description: "This is an alternative version may be more robust to accidental mistakes. First appeared on [blog](https://eli.thegreenplace.net/2024/locally-patching-dependencies-in-go)."
commands:
- "# clone your dependency to $DEP folder"
- "# make changes"
- go work init
- go work use . $DEP
- title: Code Visualization
entries:
- title: Make C4 diagram
description: This library provides tools to generate [C4](https://c4model.com) diagrams. The process is a bit involved, however you get diagram generated from real Go code automatically. Steps are outlined in [blog](https://threedots.tech/post/auto-generated-c4-architecture-diagrams-in-go/).
url: https://github.com/krzysztofreczek/go-structurizr
author: https://github.com/krzysztofreczek
name: go-structurizr
example_image_url: https://threedots.tech/post/auto-generated-c4-architecture-diagrams-in-go/tdl-go_structurizr_1_2.png
requirements:
- manually defining Go main.go script to invoke library
- graphviz
- manual coloring spec (DB, classes)
- title: Make graph of function calls
description: Visualize complex or new project quickly or to study project. Requires `main.go` in module. Supports Graphviz output format. Has many options for filtering and formatting.
name: callgraph
url: https://golang.org/x/tools/cmd/callgraph
author: official Go team
example_image_url: img/callgraph.svg
commands:
- callgraph -format graphviz . | dot -Tsvg -o graph.svg
- "recommend: grep <package/class/func of interest>"
- "recommend: grep -v Error since many packages report error"
- "recommend: adding `rankdir=LR;` to graphviz file for denser graph"
- "recommend: you would have to manually fix graphviz file first and last line"
requirements:
- go install golang.org/x/tools/cmd/callgraph@latest
- title: Make graph of function calls in package
description: Quickly track which packages current package is calling and why.
name: go-callvis
url: https://github.com/ofabry/go-callvis
author: https://github.com/ofabry
commands:
- go-callvis .
example_image_url: https://raw.githubusercontent.com/ofabry/go-callvis/master/images/syncthing.png
requirements:
- go install github.com/ofabry/go-callvis
- title: Make PlantUML diagram
description: Generates class diagram in widely used format with the information on structs, interfaces and their relationships. Render `.puml` files in for example [planttext.com](https://www.planttext.com).
name: goplantuml
url: https://github.com/jfeliu007/goplantuml
author: https://github.com/jfeliu007
commands:
- goplantuml -recursive path/to/gofiles path/to/gofiles2
requirements:
- go get github.com/jfeliu007/goplantuml/parser
- go install github.com/jfeliu007/goplantuml/cmd/goplantuml@latest
example_image_url: https://raw.githubusercontent.com/jfeliu007/goplantuml/master/example/example.png
- title: Make PlantUML diagram
description: Automatically generate visualization of classes and interfaces for go packages. Recommend recursive option. Render `.puml` files in for example [planttext.com](https://www.planttext.com).
name: go-plantuml
url: https://github.com/bykof/go-plantuml
author: https://github.com/bykof
commands:
- go-plantuml generate -d . -r -o graph.puml
example_image_url: https://raw.githubusercontent.com/bykof/go-plantuml/master/docs/assets/graph.svg
requirements:
- go install github.com/bykof/go-plantuml@latest
- title: ":fire: Visualize the entropy of a code base with a 3D force-directed graph"
description: This excellent interactive visualisation tool lets you explore code base as 3D graph. The more decoupled and modular a code base is, the more spread and clustered the graph will look like.
name: dep-tree
url: https://github.com/gabotechs/dep-tree
author: https://github.com/gabotechs
example_image_url: https://github.com/gabotechs/dep-tree/blob/main/docs/demo.gif
- title: Make 3D chart of Go codebase
description: Fresh artistic perspective on Go codebase. `GoCity` is an implementation of the Code City metaphor for visualizing source code - folders are districts; files are buildings; structs are buildings on the top of their files. This project has research paper "[GoCity Code City for Go](https://homepages.dcc.ufmg.br/~mtov/pub/2019-saner-gocity.pdf)" at SANER'19. Also available at [go-city.github.io](https://go-city.github.io).
example_image_url: img/gocity.png
name: gocity
url: https://github.com/rodrigo-brito/gocity
author: https://github.com/rodrigo-brito
requirements:
- go install github.com/rodrigo-brito/gocity@latest
- title: Make histogram of Go files per package
description: Find when package is too big or too small. Adjust histogram length to maximum value.
requirements:
- https://stedolan.github.io/jq/download/
commands:
- go list -json ./... | jq -rc '[.ImportPath, (.GoFiles | length | tostring)] | join(" ")' | perl -lane 'print (" " x (20 - $F[1]), "=" x $F[1], " ", $F[1], "\t", $F[0])'
example_output: |
================== 18 github.com/gin-gonic/gin
============= 13 github.com/gin-gonic/gin/binding
= 1 github.com/gin-gonic/gin/internal/bytesconv
= 1 github.com/gin-gonic/gin/internal/json
=========== 11 github.com/gin-gonic/gin/render
- title: Explore Go code in browser powered by `go-guru`
description: "Explore Go source code in browser. It provides exported symbols summary for navigation. It answers questions like: definition; callers; implementers. It is browser frontend based on [go-guru](https://docs.google.com/document/d/1_Y9xCEMj5S-7rv2ooHpZNH15JgRT5iM742gJkw5LtmQ/edit), which was developed by Go core team from Google."
url: https://github.com/fzipp/pythia
name: pythia
author: https://github.com/fzipp
example_image_url: https://camo.githubusercontent.com/a7baec2bada145869272edf97d1123d1717ed68922c159b027d261bd6e1faeff/68747470733a2f2f7261772e6769746875622e636f6d2f667a6970702f7079746869612f67682d70616765732f696d616765732f7079746869615f73637265656e73686f742e706e67
commands:
- pythia net/http
requirements:
- go install github.com/fzipp/pythia@latest
- go install golang.org/x/tools/cmd/guru@latest
- title: "Interactively visualize packages"
description: Based on `go-callvis`, this tool is an interactive package explorer of packages. This tool have not been updated for a long time.
url: https://github.com/ofabry/goexplorer
name: goexplorer
author: https://github.com/ofabry
example_image_url: https://github.com/ofabry/goexplorer/raw/master/images/screen.png
- title: Make D2 graph of architecture and dependencies
description: "Can include vendors or not, and be of type 'flow' or 'di'."
name: go-arch-lint graph
url: https://github.com/fe3dback/go-arch-lint
author: https://github.com/fe3dback
example_image_url: https://github.com/fe3dback/go-arch-lint/blob/master/docs/images/graph-example.png
requirements:
- go install github.com/fe3dback/go-arch-lint@latest
commands:
- go-arch-lint graph
- title: Code Generation
entries:
- title: Run `go:generate` in parallel
description: Official Go team [encourages](https://github.com/golang/go/issues/20520) to run sequentially. However, in certain situations, such as lots of mocks, parallelization helps a lot, albeit, you should consider including your generated files in git. The solution below spawns multiple processes, each per pkg.
commands:
- grep -rnw "go:generate" -E -l "${1:-*.go}" . | xargs -L1 dirname | sort -u | xargs -P 8 -I{} go generate {}
- title: Generate `String` method for enum types
description: This is an official tool for generating `String` for enums. It supports overrides via comments.
author: official Go team
example_content_ext: go
example_content: |
package painkiller
//go:generate stringer -type=Pill -linecomment
type Pill int
const (
Placebo Pill = iota
Ibuprofen
Paracetamol
PillAspirin // Aspirin
Acetaminophen = Paracetamol
)
// "Acetaminophen"
var s string = Acetaminophen.String()
requirements:
- go install golang.org/x/tools/cmd/stringer@latest
- title: ":fire: Generate enums encoding"
name: go-enum-encoding
description: Generate encoding code for enums. This follows json struct tag notation.
author: https://github.com/nikolaydubina
url: https://github.com/nikolaydubina/go-enum-encoding
commands:
- go generate ./...
example_content_ext: go
example_content: |
type Color struct{ c uint }
//go:generate go-enum-encoding -type=Color
var (
Undefined = Color{} // json:"-"
Red = Color{1} // json:"red"
Green = Color{2} // json:"green"
Blue = Color{3} // json:"blue"
)
requirements:
- go install github.com/nikolaydubina/go-enum-encoding@latest
- title: ":fire: Generate enums"
name: goenums
description: Generate strict and fast enums. Generated code is much more tightly typed than just iota defined enums. You will get JSON decoder and encoder as well. This tool allows to generate extra fields and default values in enum structs.
author: https://github.com/zarldev
url: https://github.com/zarldev/goenums
commands:
- goenums <file-with-iota.go>
example_content_ext: go
requirements:
- go install github.com/zarldev/goenums@latest
example_content: |
package milkyway
type planet int // Gravity[float64],RadiusKm[float64],MassKg[float64],OrbitKm[float64],OrbitDays[float64],SurfacePressureBars[float64],Moons[int],Rings[bool]
//go:generate goenums planets.go
const (
unknown planet = iota // invalid
mercury // Mercury 0.378,2439.7,3.3e23,57910000,88,0.0000000001,0,false
venus // Venus 0.907,6051.8,4.87e24,108200000,225,92,0,false
earth // Earth 1,6378.1,5.97e24,149600000,365,1,1,false
mars // Mars 0.377,3389.5,6.42e23,227900000,687,0.01,2,false
jupiter // Jupiter 2.36,69911,1.90e27,778600000,4333,20,4,true
saturn // Saturn 0.916,58232,5.68e26,1433500000,10759,1,7,true
uranus // Uranus 0.889,25362,8.68e25,2872500000,30687,1.3,13,true
neptune // Neptune 1.12,24622,1.02e26,4495100000,60190,1.5,2,true
)
- title: "Generate data types from JSON Schema"
url: https://github.com/omissis/go-jsonschema
author: https://github.com/omissis
name: go-jsonschema
requirements:
- go get github.com/atombender/go-jsonschema/...
- go install github.com/atombender/go-jsonschema@latest
description: JSON Schema is widely used standard for definition of structured data types. This tool will generate Go struct, decoder and validation based on JSON Schema spec.
commands:
- go-jsonschema -p main myschema.jsonschema
example_output: |
{
"$id": "https://example.com/arrays.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A representation of a person, company, organization, or place",
"type": "object",
"properties": {
"fruits": {
"type": "array",
"items": {
"type": "string"
}
},
"vegetables": {
"type": "array",
"items": {
"$ref": "#/$defs/veggie"
}
}
},
"$defs": {
"veggie": {
"type": "object",
"required": [
"veggieName",
"veggieLike"
],
"properties": {
"veggieName": {
"type": "string",
"description": "The name of the vegetable."
},
"veggieLike": {
"type": "boolean",
"description": "Do I like this vegetable?"
}
}
}
}
}
example_content_ext: go
example_content: |
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.
package main
import "encoding/json"
import "fmt"
type Veggie struct {
// Do I like this vegetable?
VeggieLike bool `json:"veggieLike" yaml:"veggieLike" mapstructure:"veggieLike"`
// The name of the vegetable.
VeggieName string `json:"veggieName" yaml:"veggieName" mapstructure:"veggieName"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Veggie) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["veggieLike"]; !ok || v == nil {
return fmt.Errorf("field veggieLike in Veggie: required")
}
if v, ok := raw["veggieName"]; !ok || v == nil {
return fmt.Errorf("field veggieName in Veggie: required")
}
type Plain Veggie
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Veggie(plain)
return nil
}
// A representation of a person, company, organization, or place
type A2Schema struct {
// Fruits corresponds to the JSON schema field "fruits".
Fruits []string `json:"fruits,omitempty" yaml:"fruits,omitempty" mapstructure:"fruits,omitempty"`
// Vegetables corresponds to the JSON schema field "vegetables".
Vegetables []Veggie `json:"vegetables,omitempty" yaml:"vegetables,omitempty" mapstructure:"vegetables,omitempty"`
}
- title: "Generate constructor for a struct"
description: Constructor is a widely used useful pattern. This tool generates basic version of it that passes arguments to struct. It also supports initializer method.
url: https://github.com/moznion/gonstructor
name: gonstructor
author: https://github.com/moznion
example_content_ext: go
example_content: |
//go:generate gonstructor --type=Structure --constructorTypes=allArgs
type Structure struct {
foo string
bar io.Reader
Buz chan interface{}
}
example-output: |
func NewStructure(foo string, bar io.Reader, buz chan interface{}) *Structure {
return &Structure{foo: foo, bar: bar, Buz: buz}
}
requirements:
- go install golang.org/x/tools/cmd/goimports@latest
- go install github.com/moznion/gonstructor/cmd/gonstructor@latest
- title: Generate Table Driven Tests
description: This tool generates basic test placeholder. It is included into official Go plugin in VSCode and other major code editors.
name: gotests
url: https://github.com/cweill/gotests
author: https://github.com/cweill
example_image_url: https://github.com/cweill/GoTests-Sublime/raw/master/gotests.gif
- title: Generate mocks
description: This mocking framework integrates well with Go `testing` package.
author: Go Core team
name: mockgen
url: https://github.com/golang/mock
commands: