Skip to content

Commit

Permalink
add some bugs and q&a pages
Browse files Browse the repository at this point in the history
  • Loading branch information
zigo101 committed Jul 11, 2024
1 parent 6788354 commit c2b2567
Show file tree
Hide file tree
Showing 26 changed files with 1,423 additions and 36 deletions.
7 changes: 4 additions & 3 deletions go101.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
//"errors"
"go/build"
"html"
"html/template"
"io/ioutil"
"log"
Expand Down Expand Up @@ -170,8 +171,8 @@ func (go101 *Go101) RenderArticlePage(w http.ResponseWriter, r *http.Request, gr
w.Write(page)
}

var H1, _H1 = []byte("<h1>"), []byte("</h1>")
var H2, _H2 = []byte("<h2>"), []byte("</h2>")
var H1, _H1 = []byte("<h1"), []byte("</h1>")
var H2, _H2 = []byte("<h2"), []byte("</h2>")

const MaxTitleLen = 256

Expand Down Expand Up @@ -209,7 +210,7 @@ func retrieveArticleContent(group, file string) (Article, error) {
if titleStart < 0 {
//log.Println("retrieveTitlesForArticle failed:", group, file)
} else {
article.Title = article.Content[titleStart:contentStart]
article.Title = template.HTML(html.UnescapeString(string(article.Content[titleStart:contentStart])))
article.Content = article.Content[contentStart:]
k, s := 0, make([]rune, 0, MaxTitleLen)
for _, r := range article.Title {
Expand Down
48 changes: 36 additions & 12 deletions pages/apps-and-libs/golds.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,22 @@ <h2 class='tmd-header-2'>FAQ</h2>

<div class='tmd-disclosure_box'>

<details><summary>
What does <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span> mean?
</summary>
<details>
<summary></summary>
<div class='tmd-disclosure_box-content'>
<div class='tmd-usual'>
## What does <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span> mean?
</div>

<div class='tmd-base'>
<p></p>

<div class='tmd-usual'>
"Golds" is an abbreviation of <span class='tmd-bold'>Go</span> <span class='tmd-bold'>l</span>ocal <span class='tmd-bold'>d</span>ocs <span class='tmd-bold'>s</span>erver. It also means <span class='tmd-bold'>Go</span> <span class='tmd-bold'>l</span>ocal <span class='tmd-bold'>d</span>irectory <span class='tmd-bold'>s</span>erver.
</div>

</div>

</div></details>

</div>
Expand All @@ -413,10 +419,14 @@ <h2 class='tmd-header-2'>FAQ</h2>

<div class='tmd-disclosure_box'>

<details><summary>
Why <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span>?
</summary>
<details>
<summary></summary>
<div class='tmd-disclosure_box-content'>
<div class='tmd-usual'>
## Why <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span>?
</div>

<div class='tmd-base'>
<p></p>

<div class='tmd-usual'>
Expand All @@ -439,6 +449,8 @@ <h2 class='tmd-header-2'>FAQ</h2>
Golds also tries to fix some other shortcomings of <code class='tmd-code-span'>godoc</code> and <code class='tmd-code-span'>go doc</code>, such as <a href='https://github.com/golang/go/issues/6600'>this</a>, <a href='https://github.com/golang/go/issues/40360'>this</a> and <a href='https://github.com/golang/go/issues/5860'>this</a>.
</div>

</div>

</div></details>

</div>
Expand All @@ -447,16 +459,22 @@ <h2 class='tmd-header-2'>FAQ</h2>

<div class='tmd-disclosure_box'>

<details><summary>
Is <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span> recommended to run locally?
</summary>
<details>
<summary></summary>
<div class='tmd-disclosure_box-content'>
<div class='tmd-usual'>
## Is <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span> recommended to run locally?
</div>

<div class='tmd-base'>
<p></p>

<div class='tmd-usual'>
Yes. But if you do want to serve your package docs on Internet, it is best to serve the generated HTML static doc pages to lower the server cost.
</div>

</div>

</div></details>

</div>
Expand All @@ -465,10 +483,14 @@ <h2 class='tmd-header-2'>FAQ</h2>

<div class='tmd-disclosure_box'>

<details><summary>
What are the requirements to run <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span>?
</summary>
<details>
<summary></summary>
<div class='tmd-disclosure_box-content'>
<div class='tmd-usual'>
## What are the requirements to run <span class='tmd-bold'><span class='tmd-italic'>Golds</span></span>?
</div>

<div class='tmd-base'>
<p></p>

<div class='tmd-usual'>
Expand All @@ -481,6 +503,8 @@ <h2 class='tmd-header-2'>FAQ</h2>
Some projects might need large memory capacity to analyze. For example, the recommended memory capacity to analyze the Kubernetes project is 8G+. However, 500M to 2G memory is okay for most Go projects.
</div>

</div>

</div></details>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ <h3 class='tmd-header-3'>Specify Go language versions for Go source files</h3>
<li>

<div class='tmd-usual'>
Add a <code class='tmd-code-span'>//go:build go1.xy</code> comment directive at the start of a source file to specify the language version for the source file. <span class='tmd-italic'>(However, the <code class='tmd-code-span'>//go:build go1.xy</code> comment directive in a Go source file might still be ignored due to potential bugs in the toolchain implementation. For example, the Go core team is not willing to fix </span><a href='https://github.com/golang/go/issues/66092'><span class='tmd-italic'>this known bug</span></a><span class='tmd-italic'> for Go toolchain v1.22.x and v1.23.x versions.)</span>
Add a <code class='tmd-code-span'>//go:build go1.xy</code> comment directive at the start of a source file to specify the language version for the source file. <span class='tmd-italic'>(However, the <code class='tmd-code-span'>//go:build go1.xy</code> comment directive in a Go source file might still be ignored due to potential bugs in the toolchain implementation. For example, the Go core team is not willing to fix </span><a href='https://github.com/golang/go/issues/66092'><span class='tmd-italic'>this known bug</span></a><span class='tmd-italic'> for Go toolchain v1.22.x versions.)</span>
</div>

</li>
Expand Down
22 changes: 11 additions & 11 deletions pages/blog/2024-03-01-for-loop-semantic-changes-in-go-1.22.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ For a language that promotes explicitness, it's embarrassing.
Implicitness often leads to unexpected surprises, which is not a surprise.
The following will show several cases which might break your expectations.

##:::::::::::::::::::::::::::::::::::::
##++++++++++++++
The behaviors of deferred function calls which capture loop variables might change

A simple example:
Expand Down Expand Up @@ -373,7 +373,7 @@ for counter, n := 0, 2; n >= 0; n := n - 1 { ... }
However, sadly, the suggestion was ignored totally.
}

##:::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Be careful when capturing loop variables in closures

An example:
Expand Down Expand Up @@ -471,7 +471,7 @@ since Go 1.22, a freshly-declared loop variable may have many instances at run t
whether or not it is modified in `postStatement`.
Each of the instances is instantiated in one iteration.

##::::::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Be careful when taking addresses of loop variables

Similarly, since Go 1.22, it may be dangerous to use
Expand Down Expand Up @@ -564,7 +564,7 @@ $ gotv 1.22. run demo-pointer2.go
...
'''

##::::::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Be careful when moving the 3rd clause statements inside loop bodies

Since Go 1.22, the following two loops might be not equivalent with each other any more
Expand Down Expand Up @@ -623,7 +623,7 @@ true
2
'''

##::::::::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Be careful when declaring no-copy values as loop variables

As explained above, since Go 1.22, at the start of each loop iteration,
Expand Down Expand Up @@ -774,7 +774,7 @@ This is just a suggestion, not a mandatory rule,
because copying no-copy values does not always cause damage
(but the damage may be exposed later when the code is refactored in some way).

##:::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Warning: the performance of your Go programs might be degraded silently

Sometimes, a compiler is over smart; sometimes, it is not smart enough.
Expand Down Expand Up @@ -853,7 +853,7 @@ Suggestions to avoid such performance degradation issue:
the loop itself to optimize performance. This is beneficial if you can
guarantee that the variables don't need to be instantiated in each iteration.

##::::::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Warning: things might become more subtle than before when loop variables are used concurrently

Firstly, let's view a simple program.
Expand Down Expand Up @@ -1056,7 +1056,7 @@ There might be more, I'm not sure.

Here are some recommendations you can follow in the Go 1.22+ era.

##::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Specify Go language versions for Go source files

As demonstrated in many above examples, the semantic changes made
Expand All @@ -1072,7 +1072,7 @@ for Go source files:
%% (However, the `//go:build go1.xy` comment directive in a Go source file might
still be ignored due to potential bugs in the toolchain implementation.
For example, the Go core team is not willing to fix __this known bug__ for
Go toolchain v1.22.x and v1.23.x versions.)
Go toolchain v1.22.x versions.)
+. Use `-gcflags=-lang=go1.xy` compiler option when building a
Go binary to specify the Go language version for the seed files
you're passing to the compiler.
Expand Down Expand Up @@ -1106,7 +1106,7 @@ Anyway, since Go 1.22, you should try to specify a Go language version for every
in any of the above introduced ways, to avoid compiler version dependent behaviors.
This is the minimum standard to be a professional Go programmer in the Go 1.22+ era.

##::::::::::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Upgrading module versions

If you are maintaining a public Go module which are depended by other Go projects,
Expand All @@ -1120,7 +1120,7 @@ pay attention to those ones which language versions os
upgraded to Go 1.22 or higher
from a version with the old semantics before Go 1.22.

##::::::::::::::::::::::::::::::::::::::::::::
##++++++++++++++
Avoid using freshly-declared loop variables in `for;;` loops
if you worry about getting bitten by the pitful of the new semantics

Expand Down
10 changes: 10 additions & 0 deletions pages/bugs/101.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ <h1 class='tmd-header-1'>Go Bugs 101</h1>

</li>

<li>

<div class='tmd-usual'>
<a href='https://go101.org/bugs/package-level-variable-initialization-order-bugs.html'>Some known package-level variable initialization order bugs in certain Go toolchain versions</a>
</div>

<div></div>

</li>

</ul>

<p></p>
2 changes: 2 additions & 0 deletions pages/bugs/101.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Index:
////__...`` https://go101.org/bugs/go-build-directive-not-work.html
* __A channel comparison bug when channels are used as `case` expressions of `switch` code blocks (in Go toolchain v1.20 - v1.23.x)
////__...`` https://go101.org/bugs/a-switch-case-channel-comparison-bug.html
* __Some known package-level variable initialization order bugs in certain Go toolchain versions
////__...`` https://go101.org/bugs/package-level-variable-initialization-order-bugs.html
2 changes: 1 addition & 1 deletion pages/bugs/go-build-directive-not-work.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h1 class='tmd-header-1'>The <code class='tmd-code-span'>//go:build go1.mn</code
<p></p>

<div class='tmd-usual'>
The Go core team deliberately <a href='https://github.com/golang/go/issues/66092#issuecomment-2192570381'>refused to fix the bug for coming 1.22.x versions</a>. So ou should be aware of the fact that the bug will be always in 1.22.x versions when you are using these versions of the Go toolchain.
The Go core team deliberately <a href='https://github.com/golang/go/issues/66092#issuecomment-2192570381'>refused to fix the bug for coming 1.22.x versions</a>. So you should be aware of the fact that the bug will be always in 1.22.x versions when you are using these Go toolchain versions.
</div>

<p></p>
Expand Down
4 changes: 2 additions & 2 deletions pages/bugs/go-build-directive-not-work.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ $ gotv 1.23. run example.go

The Go core team deliberately __refused to fix the bug
for coming 1.22.x versions__.
So ou should be aware of the fact that the bug will be always
in 1.22.x versions when you are using these versions of the Go toolchain.
So you should be aware of the fact that the bug will be always
in 1.22.x versions when you are using these Go toolchain versions.

////__refused ... `` https://github.com/golang/go/issues/66092#issuecomment-2192570381

Expand Down
Loading

0 comments on commit c2b2567

Please sign in to comment.