Golang Tips

[Phuong Le](https://twitter.com/func25)によるGolang Tips

Xを徘徊していて有益そうなPostを見かけたのでまとめておく。ちゃんと読んだら別記事で翻訳しながら勉強したいと思っている。

#8, #10, #11, #24 は見つけられなかった。もしご存じの方あればコメントいただけると嬉しいです。

| # | URL |
| --: | :-- |
| 1 | [[翻訳転載] Golang Tip #1: 1行のコードで関数の実行時間を計測する](https://qiita.com/a10a/items/96cabcdcf60481480145) |
| 2 | [[翻訳転載] Golang Tip #2: マルチステージdefer](https://qiita.com/a10a/items/890dee753883decbfd42) |
| 3 | [[翻訳転載] Golang Tip #3: パフォーマンスを考慮したスライスの初期化](https://qiita.com/a10a/items/6945dbafbff7a8f80365) |
| 4 | [[翻訳転載] Golang Tip #4: 配列をスライスにパースする](https://qiita.com/a10a/items/221bd4c799541f7750e1) |
| 5 | [[翻訳転載] Golang Tip #5: メソッドチェーン](https://qiita.com/a10a/items/df12c7dfb442194bca95) |
| 6 | [[翻訳転載] Golang Tip #6: アンダースコア Import](https://qiita.com/a10a/items/aaaab9645933019b6d93) |
| 7 | [[翻訳転載] Golang Tip #7: 三項演算子](https://qiita.com/a10a/items/228d5442be3eb77961d7) |
| 8 | |
| 9 | [[翻訳転載] Golang Tip #9: コンパイル時のインターフェイス検証](https://qiita.com/a10a/items/90c449854647de6b622c) |
| 10 | |
| 11 | |
| 12 | [[翻訳転載] Golang Tip #12: 鍵作成時はmath/randの使用を避ける](https://qiita.com/a10a/items/4789dfd0b605956506a6) |
| 13 | [[翻訳転載] Golang Tip #13: 空スライスとnilスライス](https://qiita.com/a10a/items/87014388f50c2dbf0236) |
| 14 | [[翻訳転載] Golang Tip #14: エラーメッセージを大文字で始めたり区切り記号で終えたりしない](https://qiita.com/a10a/items/4dd069913a1eec41005a) |
| 15 | [When to use Dot (.) Import and Blank (_) Import](https://x.com/func25/status/1755544355572765179?s=20) |
| 16 | [Don't Return -1 or nil to Indicate Error](https://x.com/func25/status/1755903433671106993?s=20) |
| 17 | [Understanding "Return fast, return early" to avoid nested code](https://x.com/func25/status/1756271704324845722?s=20) |
| 18 | [Define interfaces in the consumer package, not the producer](https://x.com/func25/status/1756629777107292231?s=20) |
| 19 | [Avoid named results unless necessary for documentation](https://x.com/func25/status/1757024709605265674?s=20) |
| 20 | [Pass values, not pointers](https://x.com/func25/status/1757387675085279437?s=20) |
| 21 | [[翻訳転載] Golang Tip #21: ポインタレシーバの推奨](https://qiita.com/a10a/items/9c0725dc4011e090d488) |
| 22 | [[翻訳転載] Golang Tip #22: 構造体やオプションパターンを使って関数のシグネチャをシンプルにする](https://qiita.com/a10a/items/838f26a2ebf857e817f2) |
| 23 | [Avoid repetition in naming](https://x.com/func25/status/1759196416961032620?s=20) |
| 24 | |
| 25 | [Prefer 'chan struct{}' over 'chan bool' for signaling between goroutines](https://twitter.com/func25/status/1759526542877839447) |
| 26 | [Explicitly ignore values with blank identifier (_) instead of silently ignoring them](https://x.com/func25/status/1759900581315870883?s=20) |
| 27 | [Filter without any allocation](https://x.com/func25/status/1760288508600590594?s=20) |
| 28 | [Converting multiple if-else statements into switch cases](https://x.com/func25/status/1760648317942600114?s=20) |
| 29 | [Avoid context.Background(), make your goroutines promisable](https://x.com/func25/status/1761025801716392106?s=20) |
| 30 | [Keep contexts going with context.WithoutCancel()](https://x.com/func25/status/1761388781201174853?s=20) |
| 31 | [Loop labels for cleaner breaks and continues](https://x.com/func25/status/1761694371240702098?s=20) |
| 32 | [Scheduling functions after context cancellation with context.AfterFunc](https://x.com/func25/status/1762087461839364445?s=20) |
| 33 | [Just... Don’t Panic()](https://x.com/func25/status/1762455704903029138?s=20) |
| 34 | [Lead with context, end with options, and always close with an error](https://x.com/func25/status/1762798519696732567?s=20) |
| 35 | [Prefer strconv over fmt for converting to/from string](https://x.com/func25/status/1763187911942660330?s=20) |
| 36 | [Naming Unexported Global Variables with an Underscore (_) Prefix](https://x.com/func25/status/1763527891466522656?s=20) |
| 37 | [Using Unexported Empty Struct as Context Key](https://x.com/func25/status/1763897057511899516?s=20) |
| 38 | [Make your errors clear with fmt.Errorf, don't just leave them bare](https://x.com/func25/status/1764265328165753176?s=20) |
| 39 | [Avoid defer in loops, or your memory might blow up](https://x.com/func25/status/1764606374519230540?s=20) |
| 40 | [Handle errors while using defer to prevent silent failures](https://x.com/func25/status/1764997813501608144?s=20) |
| 41 | [Sort your fields in your struct from largest to smallest](https://x.com/func25/status/1765371933053612110?s=20) |
| 42 | [Single Touch Error Handling, Less Noise](https://x.com/func25/status/1765716456501817766?s=20) |
| 43 | [Gracefully Shut Down Your Application](https://x.com/func25/status/1766104130303705226?s=20) |
| 44 | [Intentionally Stop with Must Functions](https://x.com/func25/status/1766442686624784496?s=20) |
| 45 | [Always Manage Your Goroutine Lifetime](https://x.com/func25/status/1766815880745533712?s=20) |
| 46 | [Avoid using break in switch cases, except when paired with labels](https://x.com/func25/status/1767165749116948584?s=20) |
| 47 | [Table-driven tests, subtests, and parallel tests](https://x.com/func25/status/1767541900960276913?s=20) |
| 48 | [Avoid Global Variables, Especially Mutable Ones](https://x.com/func25/status/1767903551303586048?s=20) |
| 49 | [Give the Caller the Right to Make Decisions](https://x.com/func25/status/1768270595521929430?s=20) |
| 50 | [Make Structs Non-comparable](https://x.com/func25/status/1768621711929311620?s=20) |
| 51 | [Avoid using init()](https://x.com/func25/status/1769002177643860116?s=20) |
| 52 | [Adjusting GOMAXPROCS for Containerized Env (Kubernetes, Docker, etc.)](https://x.com/func25/status/1769315593122177195?s=20) |
| 53 | [Enums start from 1 for categorization and 0 for default cases](https://x.com/func25/status/1769707703939817561?s=20) |