Skip to content

Commit

Permalink
sync with latest TapirMD format
Browse files Browse the repository at this point in the history
  • Loading branch information
zigo101 committed Nov 2, 2024
1 parent 6693cfe commit 4db9add
Show file tree
Hide file tree
Showing 31 changed files with 1,833 additions and 148 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module go101.org/go101

go 1.16

require golang.org/x/sys v0.26.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var genFlag = flag.Bool("gen", false, "HTML generation mode?")
var themeFlag = flag.String("theme", "", "theme (dark | light)")
var nobFlag = flag.Bool("nob", false, "not open browswer?")

var listenConfig net.ListenConfig

func main() {
log.SetFlags(0)
flag.Parse()
Expand All @@ -34,7 +36,8 @@ func main() {
}

Retry:
l, err := net.ListenTCP("tcp", addr)
//l, err := net.ListenTCP("tcp", addr)
l, err := listenConfig.Listen(context.Background(), "tcp", addr.String())
if err != nil {
if strings.Index(err.Error(), "bind: address already in use") >= 0 {
addr.Port++
Expand Down
21 changes: 21 additions & 0 deletions net_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"net"
"syscall"
"golang.org/x/sys/unix"
)

func init() {
listenConfig = net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
var opErr error
if err := c.Control(func(fd uintptr) {
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
}); err != nil {
return err
}
return opErr
},
}
}
21 changes: 21 additions & 0 deletions net_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"net"
"syscall"
"golang.org/x/sys/unix"
)

func init() {
listenConfig = net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
var opErr error
if err := c.Control(func(fd uintptr) {
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
}); err != nil {
return err
}
return opErr
},
}
}
21 changes: 21 additions & 0 deletions net_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"net"
"syscall"
"golang.org/x/sys/windows"
)

func init() {
listenConfig = net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
var opErr error
if err := c.Control(func(fd uintptr) {
opErr = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
}); err != nil {
return err
}
return opErr
},
}
}
12 changes: 0 additions & 12 deletions pages/apps-and-libs/101.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ <h1 class="tmd-header-1">
<a href="golds.html">Golds</a> - an experimental <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, a Go docs generator, and a Go code reader.
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -28,10 +24,6 @@ <h1 class="tmd-header-1">
<a href="gotv.html">GoTV</a> - a tool used to install and use coexisting installations of <span class="tmd-bold">Go</span> <span class="tmd-bold">t</span>oolchain <span class="tmd-bold">v</span>erisons harmoniously.
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -40,10 +32,6 @@ <h1 class="tmd-header-1">
<a href="nstd.html">nstd</a> - a single-package go module which provides some missing types and functions in the standard library.
</div>

<div class="tmd-usual index">

</div>

</li>

</ul>
Expand Down
3 changes: 0 additions & 3 deletions pages/apps-and-libs/101.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
"""

* __Golds__ - an experimental **Go** **l**ocal **d**ocs **s**erver, a Go docs generator, and a Go code reader.
@@@ .index
// __...`` golds.html
* __GoTV__ - a tool used to install and use coexisting installations of **Go** **t**oolchain **v**erisons harmoniously.
@@@ .index
// __...`` gotv.html
* __nstd__ - a single-package go module which provides some missing types and functions in the standard library.
@@@ .index
// __...`` nstd.html


Expand Down
6 changes: 6 additions & 0 deletions pages/apps-and-libs/nstd.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ <h1 class="tmd-header-1">

<p></p>

<div class="tmd-usual">
Docs page: <a href="https://docs.go101.org/std/pkg/go101.org/nstd.html">https://docs.go101.org/std/pkg/go101.org/nstd.html</a>
</div>

<p></p>

<div class="tmd-usual">
Module path: <span class="tmd-bold"><span class="tmd-italic">go101.org/nstd</span></span>
</div>
Expand Down
2 changes: 2 additions & 0 deletions pages/apps-and-libs/nstd.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ some missing types and functions in the standard library.

Project page: __https://github.com/go101/nstd__

Docs page: __https://docs.go101.org/std/pkg/go101.org/nstd.html__

Module path: **%% go101.org/nstd

Please follow __@zigo_101__ to get the latest news of `nstd`
Expand Down
24 changes: 0 additions & 24 deletions pages/blog/101.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ <h1 class="tmd-header-1">
<a href="2024-03-01-for-loop-semantic-changes-in-go-1.22.html"><code class="tmd-code-span">for</code>-loop semantic changes in Go 1.22: be aware of the impact</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -28,10 +24,6 @@ <h1 class="tmd-header-1">
<a href="2022-12-30-go-builtin-slice-manipulations-are-incomplete.html">Go built-in slice manipulations are incomplete</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -40,10 +32,6 @@ <h1 class="tmd-header-1">
<a href="2022-11-18-constant-string-elements-are-not-constants.html">It is a pity that byte elements of Go constant strings are not constants. And it is a luck.</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -52,10 +40,6 @@ <h1 class="tmd-header-1">
<a href="2022-10-01-three-way-string-comparison.html">No safe efficient ways to do three-way string comparisons in Go</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -64,10 +48,6 @@ <h1 class="tmd-header-1">
<a href="2022-08-22-some-undocumented-changes-in-go-1.18-and-1.19.html">Some undocumented changes in Go 1.18 and 1.19</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -76,10 +56,6 @@ <h1 class="tmd-header-1">
<a href="2022-02-22-history.html">Update Histories of Go 101 Books</a>
</div>

<div class="tmd-usual index">

</div>

</li>

</ul>
Expand Down
6 changes: 0 additions & 6 deletions pages/blog/101.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@
"""

* __`for`-loop semantic changes in Go 1.22: be aware of the impact
@@@ .index tags="loop, semantic" date="2024-03-01"
// __...`` 2024-03-01-for-loop-semantic-changes-in-go-1.22.html
* __Go built-in slice manipulations are incomplete
@@@ .index tags="slice, merge, clip" date="2022-12-30"
// __...`` 2022-12-30-go-builtin-slice-manipulations-are-incomplete.html
* __It is a pity that byte elements of Go constant strings are not constants. And it is a luck.
@@@ .index tags="string, constant, generic" date="2022-11-18"
// __...`` 2022-11-18-constant-string-elements-are-not-constants.html
* __No safe efficient ways to do three-way string comparisons in Go
@@@ .index tags="optimization, string, compare" date="2022-10-01"
// __...`` 2022-10-01-three-way-string-comparison.html
* __Some undocumented changes in Go 1.18 and 1.19
@@@ .index tags="byte-slice, constant, type-alias, goexit" date="2022-08-22"
// __...`` 2022-08-22-some-undocumented-changes-in-go-1.18-and-1.19.html
* __Update Histories of Go 101 Books
@@@ .index tags="go101" date="2022-02-22"
// __...`` 2022-02-22-history.html


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ <h2 class="tmd-header-2">
<li class="tmd-list-item">

<div class="tmd-usual">
The wiki page: <a href="https://go.dev/wiki/LoopvarExperiment">https://go.dev/wiki/LoopvarExperiment</a>, and the blog article: <a href="https://go.dev/blog/loopvar-preview">https://go.dev/blog/loopvar-preview</a>. Both of them were created after the proposal was accepted, which means <span class="tmd-bold">the proposal was accepted before the experiment phase even began!</span> <span class="tmd-italic">(It was very unusually. The experiment phase seemed like a mere formality. This was evident in the brevity of the experiment phase period and the lack of a strong public call for participation. Consequently, the numerous problems mentioned in this article only surfaced after the proposed changes were officially released.)</span>
The wiki page: <a href="https://go.dev/wiki/LoopvarExperiment">https://go.dev/wiki/LoopvarExperiment</a>, and the blog article: <a href="https://go.dev/blog/loopvar-preview">https://go.dev/blog/loopvar-preview</a>. Both of them were created after the proposal was accepted, which means <span class="tmd-bold">the proposal was accepted before the experiment phase even began!</span> <span class="tmd-italic">(It was very unusual. The experiment phase seemed like a mere formality. This was evident in the brevity of the experiment phase period and the lack of a strong public call for participation. Consequently, the numerous problems mentioned in this article only surfaced after the proposed changes were officially released.)</span>
</div>

</li>
Expand Down Expand Up @@ -825,7 +825,7 @@ <h3 class="tmd-header-3">
<p></p>

<div class="tmd-usual">
As explained above, since Go 1.22, at the start of each loop iteration, each freshly-declared loop variable will get copied once, <span class="tmd-bold"><span class="tmd-italic">implicitly</span></span>. The implication means that, since Go 1.22, it’s generally not advisable to use no-copy values as loop variables. Examples include <code class="tmd-code-span">sync.Mutex</code>, <code class="tmd-code-span">sync/atomic.Int64</code>, <code class="tmd-code-span">bytes.Buffer</code>, and <code class="tmd-code-span">strings.Builder</code>.
As explained above, since Go 1.22, at the start of each loop iteration, each freshly-declared loop variable will get copied once, <span class="tmd-bold"><span class="tmd-italic">implicitly</span></span>. The implication means that, since Go 1.22, it’s generally not advisable to use no-copy values as loop variables. Examples include <code class="tmd-code-span">sync.Mutex</code>, <code class="tmd-code-span">sync/atomic.Int64</code>, <code class="tmd-code-span">bytes.Buffer</code>, <code class="tmd-code-span">strings.Builder</code>, and <code class="tmd-code-span">container/list.List</code>, etc.
</div>

<p></p>
Expand Down Expand Up @@ -1447,7 +1447,7 @@ <h3 class="tmd-header-3">
<p></p>

<div class="tmd-usual">
Don't be too nervous, :D. In fact, most <code class="tmd-code-span">for;;</code> loops behave the same with either the old semantics or the new semantics. But if you're unsure about the new semantics, you can always rewrite the following alike loop using the old semantics:
Don't be too nervous, :D. In fact, most <code class="tmd-code-span">for;;</code> loops behave the same with either the old semantics or the new semantics. But if you're unsure about it, you can always rewrite the following alike loops
</div>

<p></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ see
and the blog article: __https://go.dev/blog/loopvar-preview__.
Both of them were created after the proposal was accepted,
which means ** the proposal was accepted before the experiment phase even began!**
%% (It was very unusually. The experiment phase seemed like a mere formality.
%% (It was very unusual. The experiment phase seemed like a mere formality.
This was evident in the brevity of the experiment phase period and
the lack of a strong public call for participation. Consequently,
the numerous problems mentioned in this article only surfaced
Expand Down Expand Up @@ -632,7 +632,8 @@ As explained above, since Go 1.22, at the start of each loop iteration,
each freshly-declared loop variable will get copied once, **%%implicitly%%**.
The implication means that, since Go 1.22, it’s generally not advisable
to use no-copy values as loop variables.
Examples include `sync.Mutex`, `sync/atomic.Int64`, `bytes.Buffer`, and `strings.Builder`.
Examples include `sync.Mutex`, `sync/atomic.Int64`, `bytes.Buffer`, `strings.Builder`,
and `container/list.List`, etc.

For example, in Go versions prior to 1.22, the following code was considered concurrently correct.
However, starting with Go 1.22, this code is considered to have a concurrency issue,
Expand Down Expand Up @@ -1128,8 +1129,7 @@ from a version with the old semantics before Go 1.22.

Don't be too nervous, :D.
In fact, most `for;;` loops behave the same with either the old semantics or the new semantics.
But if you're unsure about the new semantics,
you can always rewrite the following alike loop using the old semantics:
But if you're unsure about it, you can always rewrite the following alike loops

'''Go
for a, b, c := anExpression; aCondition; postStatement {
Expand Down
18 changes: 5 additions & 13 deletions pages/bugs/101.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ <h1 class="tmd-header-1">
<a href="string-builders-as-iteration-variables-in-traditional-for-loops-are-bad-implemented.html"><code class="tmd-code-span">strings.Builder</code> iteration variables in traditional 3-clause <code class="tmd-code-span">for;;</code> loops are implemented incorrectly</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -34,10 +30,6 @@ <h1 class="tmd-header-1">
<a href="go-build-directive-not-work.html">The <code class="tmd-code-span">//go:build go1.mn</code> comment directives don't work with Go toolchain v1.22.x versions when no <code class="tmd-code-span">go.mod</code> files are involved</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -46,10 +38,6 @@ <h1 class="tmd-header-1">
<a href="a-switch-case-channel-comparison-bug.html">A channel comparison bug when channels are used as <code class="tmd-code-span">case</code> expressions of <code class="tmd-code-span">switch</code> code blocks (in Go toolchain v1.20 - v1.23.x)</a>
</div>

<div class="tmd-usual index">

</div>

</li>

<li class="tmd-list-item">
Expand All @@ -58,8 +46,12 @@ <h1 class="tmd-header-1">
<a href="package-level-variable-initialization-order-bugs.html">Some known package-level variable initialization order bugs in certain Go toolchain versions</a>
</div>

<div class="tmd-usual index">
</li>

<li class="tmd-list-item">

<div class="tmd-usual">
<a href="json-unmarshal-bug.html">The <code class="tmd-code-span">json.Unmarshal</code> function doesn't match object keys exactly when it should</a>
</div>

</li>
Expand Down
6 changes: 2 additions & 4 deletions pages/bugs/101.tmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ Index:
"""

* __`strings.Builder` iteration variables in traditional 3-clause `for;;` loops are implemented incorrectly
@@@ .index
// __...`` string-builders-as-iteration-variables-in-traditional-for-loops-are-bad-implemented.html
* __The `//go:build go1.mn` comment directives don't work with Go toolchain v1.22.x versions when no `go.mod` files are involved
@@@ .index
// __...`` 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)
@@@ .index
// __...`` a-switch-case-channel-comparison-bug.html
* __Some known package-level variable initialization order bugs in certain Go toolchain versions
@@@ .index
// __...`` package-level-variable-initialization-order-bugs.html
* __The `json.Unmarshal` function doesn't match object keys exactly when it should
// __...`` json-unmarshal-bug.html

"""html
<!-- index ends (don't remove) -->
Expand Down
Loading

0 comments on commit 4db9add

Please sign in to comment.