mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
Japanese, content
This commit is contained in:
parent
555f9bbdb3
commit
af8a2d0425
21 changed files with 1305 additions and 30 deletions
BIN
.cache/plugin/social/d15b238fcb5d7c473c9ad0a6aa4e7045.png
Normal file
BIN
.cache/plugin/social/d15b238fcb5d7c473c9ad0a6aa4e7045.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
6
justfile
Normal file
6
justfile
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
build:
|
||||
mkdocs build
|
||||
serve:
|
||||
mkdocs serve
|
||||
test:
|
||||
mkdocs build && mkdocs serve
|
||||
|
|
@ -49,9 +49,12 @@ extra:
|
|||
- name: 🇬🇧 English
|
||||
link: /
|
||||
lang: en
|
||||
- name: 🇨🇳 Chinese (Simplified)
|
||||
- name: 🇨🇳 Chinese Simplified
|
||||
link: /zh/
|
||||
lang: zh
|
||||
- name: 🇯🇵 Japanese (進行中)
|
||||
link: /ja/
|
||||
lang: ja
|
||||
social:
|
||||
- icon: fontawesome/brands/twitter
|
||||
link: https://twitter.com/teivah
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -172,7 +172,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
@ -980,7 +986,7 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
<p>To handle the map, we defined two kinds of type parameters. First, the values can be of any type: <code>V any</code>. However, in Go, the map keys can’t be of any type. For example, we cannot use slices:</p>
|
||||
<div class="language-go highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="kd">var</span><span class="w"> </span><span class="nx">m</span><span class="w"> </span><span class="kd">map</span><span class="p">[[]</span><span class="kt">byte</span><span class="p">]</span><span class="kt">int</span>
|
||||
</span></code></pre></div>
|
||||
<p>This code leads to a compilation error: <code>invalid map key type []byte</code>. Therefore, instead of accepting any key type, we are obliged to restrict type arguments so that the key type meets specific requirements. Here, being comparable (we can use <code>==</code> or <code>!=</code>). Hence, we defined <code>K</code> as <code>comparable</code> instead of <code>a``ny</code>.</p>
|
||||
<p>This code leads to a compilation error: <code>invalid map key type []byte</code>. Therefore, instead of accepting any key type, we are obliged to restrict type arguments so that the key type meets specific requirements. Here, being comparable (we can use <code>==</code> or <code>!=</code>). Hence, we defined <code>K</code> as <code>comparable</code> instead of <code>any</code>.</p>
|
||||
<p>Restricting type arguments to match specific requirements is called a constraint. A constraint is an interface type that can contain:</p>
|
||||
<ul>
|
||||
<li>A set of behaviors (methods)</li>
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
BIN
site/assets/images/social/ja.png
Normal file
BIN
site/assets/images/social/ja.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
|
|
@ -218,7 +218,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
8
site/external/index.html
vendored
8
site/external/index.html
vendored
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
@ -3492,7 +3498,7 @@ One additional note: we must remember that the standard library has some existin
|
|||
<h3 id="returning-a-nil-receiver-45">Returning a nil receiver (#45)</h3>
|
||||
<details class="info" open="open">
|
||||
<summary>TL;DR</summary>
|
||||
<p>When returning an interface, be cautious about returning not a nil pointer but an explicit nil value. Otherwise, unintended consequences may result because the caller will receive a non-nil value.</p>
|
||||
<p>When returning an interface, be cautious about not returning a nil pointer but an explicit nil value. Otherwise, unintended consequences may occur and the caller will receive a non-nil value.</p>
|
||||
</details>
|
||||
<!-- TODO -->
|
||||
|
||||
|
|
@ -3800,6 +3806,10 @@ the use case. However, we should see the two options as complementary. </p>
|
|||
<li>However, if the response is written before or during the Kafka publication, the message shouldn’t be published.</li>
|
||||
</ul>
|
||||
<p>In the latter case, calling publish will return an error because we returned the HTTP response quickly.</p>
|
||||
<details class="note" open="open">
|
||||
<summary>Note</summary>
|
||||
<p>From Go 1.21, there is a way to create a new context without cancel. <a href="https://pkg.go.dev/context#WithoutCancel"><code>context.WithoutCancel</code></a> returns a copy of parent that is not canceled when parent is canceled.</p>
|
||||
</details>
|
||||
<p>In summary, propagating a context should be done cautiously.</p>
|
||||
<p><a href="https://github.com/teivah/100-go-mistakes/tree/master/src/09-concurrency-practice/61-inappropriate-context/main.go">Source code <span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></span></a></p>
|
||||
<h3 id="starting-a-goroutine-without-knowing-when-to-stop-it-62">Starting a goroutine without knowing when to stop it (#62)</h3>
|
||||
|
|
@ -3867,7 +3877,7 @@ the use case. However, we should see the two options as complementary. </p>
|
|||
<p>Understanding that <code>select</code> with multiple channels chooses the case randomly if multiple options are possible prevents making wrong assumptions that can lead to subtle concurrency bugs.</p>
|
||||
</details>
|
||||
<p>One common mistake made by Go developers while working with channels is to make wrong assumptions about how select behaves with multiple channels.</p>
|
||||
<p>For example, let's consider the following case (<code>disconnectCh</code> is a buffered channel):</p>
|
||||
<p>For example, let's consider the following case (<code>disconnectCh</code> is a unbuffered channel):</p>
|
||||
<div class="language-go highlight"><pre><span></span><code><span id="__span-40-1"><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="k">go</span><span class="w"> </span><span class="kd">func</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
|
||||
</span><span id="__span-40-2"><a id="__codelineno-40-2" name="__codelineno-40-2" href="#__codelineno-40-2"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="p"><</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span><span class="w"> </span><span class="nx">i</span><span class="o">++</span><span class="w"> </span><span class="p">{</span>
|
||||
</span><span id="__span-40-3"><a id="__codelineno-40-3" name="__codelineno-40-3" href="#__codelineno-40-3"></a><span class="w"> </span><span class="nx">messageCh</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nx">i</span>
|
||||
|
|
|
|||
1179
site/ja/index.html
Normal file
1179
site/ja/index.html
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -218,7 +218,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -2,62 +2,67 @@
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://100go.co/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/20-slice/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/28-maps-memory-leaks/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/56-concurrency-faster/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/89-benchmarks/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/9-generics/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/98-profiling-execution-tracing/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/book/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/chapter-1/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/external/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/ja/</loc>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/jobs/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://100go.co/zh/</loc>
|
||||
<lastmod>2023-09-29</lastmod>
|
||||
<lastmod>2023-10-10</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
||||
Binary file not shown.
|
|
@ -216,7 +216,13 @@ This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>!
|
|||
|
||||
<li class="md-select__item">
|
||||
<a href="/zh/" hreflang="zh" class="md-select__link">
|
||||
🇨🇳 Chinese (Simplified)
|
||||
🇨🇳 Chinese Simplified
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="md-select__item">
|
||||
<a href="/ja/" hreflang="ja" class="md-select__link">
|
||||
🇯🇵 Japanese (進行中)
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue