@@ -195,8 +195,8 @@ const (
195
195
196
196
Words in names that are initialisms or acronyms (e.g., ` URL ` and ` NATO ` ) should
197
197
have the same case. ` URL ` should appear as ` URL ` or ` url ` (as in ` urlPony ` , or
198
- ` URLPony ` ), never as ` Url ` . This also applies to ` ID ` when it is short for
199
- "identifier"; write ` appID ` instead of ` appId ` .
198
+ ` URLPony ` ), never as ` Url ` . As a general rule, identifiers (e.g., ` ID ` and ` DB ` )
199
+ should also be capitalized similar to their usage in English prose .
200
200
201
201
* In names with multiple initialisms (e.g. ` XMLAPI ` because it contains ` XML `
202
202
and ` API ` ), each letter within a given initialism should have the same case,
@@ -211,7 +211,7 @@ have the same case. `URL` should appear as `URL` or `url` (as in `urlPony`, or
211
211
212
212
<!-- Keep this table narrow. If it must grow wider, replace with a list. -->
213
213
214
- Initialism(s) | Scope | Correct | Incorrect
214
+ English Usage | Scope | Correct | Incorrect
215
215
------------- | ---------- | -------- | --------------------------------------
216
216
XML API | Exported | ` XMLAPI ` | ` XmlApi ` , ` XMLApi ` , ` XmlAPI ` , ` XMLapi `
217
217
XML API | Unexported | ` xmlAPI ` | ` xmlapi ` , ` xmlApi `
@@ -221,6 +221,11 @@ gRPC | Exported | `GRPC` | `Grpc`
221
221
gRPC | Unexported | ` gRPC ` | ` grpc `
222
222
DDoS | Exported | ` DDoS ` | ` DDOS ` , ` Ddos `
223
223
DDoS | Unexported | ` ddos ` | ` dDoS ` , ` dDOS `
224
+ ID | Exported | ` ID ` | ` Id `
225
+ ID | Unexported | ` id ` | ` iD `
226
+ DB | Exported | ` DB ` | ` Db `
227
+ DB | Unexported | ` db ` | ` dB `
228
+ Txn | Exported | ` Txn ` | ` TXN `
224
229
225
230
<!-- #include file="/go/g3doc/style/includes/special-name-exception.md"-->
226
231
@@ -1779,7 +1784,7 @@ canvas.RenderCube(cube,
1779
1784
` ` `
1780
1785
1781
1786
Note that the lines in the above example are not wrapped at a specific column
1782
- boundary but are grouped based on co-ordinate triples.
1787
+ boundary but are grouped based on coordinate triples.
1783
1788
1784
1789
Long string literals within functions should not be broken for the sake of line
1785
1790
length. For functions that include such strings, a line break can be added after
@@ -2043,6 +2048,8 @@ For errors that indicate "impossible" conditions, namely bugs that should always
2043
2048
be caught during code review and/or testing, a function may reasonably return an
2044
2049
error or call [` log.Fatal ` ].
2045
2050
2051
+ Also see [when panic is acceptable](best-practices.md#when-to-panic).
2052
+
2046
2053
**Note:** ` log.Fatalf ` is not the standard library log. See [#logging].
2047
2054
2048
2055
[Effective Go section on errors]: http://golang.org/doc/effective_go.html#errors
@@ -2176,12 +2183,18 @@ clear. It is conventionally managed with a `context.Context`:
2176
2183
` ` ` go
2177
2184
// Good:
2178
2185
func (w *Worker) Run (ctx context.Context ) error {
2186
+ var wg sync.WaitGroup
2179
2187
// ...
2180
2188
for item := range w.q {
2181
2189
// process returns at latest when the context is cancelled.
2182
- go process (ctx, item)
2190
+ wg.Add (1 )
2191
+ go func () {
2192
+ defer wg.Done ()
2193
+ process (ctx, item)
2194
+ }()
2183
2195
}
2184
2196
// ...
2197
+ wg.Wait () // Prevent spawned goroutines from outliving this function.
2185
2198
}
2186
2199
` ` `
2187
2200
@@ -2222,12 +2235,14 @@ See also:
2222
2235
* Rethinking Classical Concurrency Patterns: [slides][rethinking-slides],
2223
2236
[video][rethinking-video]
2224
2237
* [When Go programs end]
2238
+ * [Documentation Conventions: Contexts]
2225
2239
2226
2240
[synchronous functions]: #synchronous-functions
2227
2241
[cheney-stop]: https://dave.cheney.net/2016/12/22/never-start-a-goroutine-without-knowing-how-it-will-stop
2228
2242
[rethinking-slides]: https://drive.google.com/file/d/1nPdvhB0PutEJzdCq5ms6UI58dp50fcAN/view
2229
2243
[rethinking-video]: https://www.youtube.com/watch?v=5zXAHh5tJqQ
2230
2244
[When Go programs end]: https://changelog.com/gotime/165
2245
+ [Documentation Conventions: Contexts]: best-practices.md#documentation-conventions-contexts
2231
2246
2232
2247
<a id="interfaces"></a>
2233
2248
@@ -2737,7 +2752,7 @@ formatting to do.
2737
2752
See also:
2738
2753
2739
2754
* Best practices on [logging errors](best-practices#error-logging) and
2740
- [custom verbosily levels](best-practices#vlog)
2755
+ [custom verbosity levels](best-practices#vlog)
2741
2756
* When and how to use the log package to
2742
2757
[stop the program](best-practices#checks-and-panics)
2743
2758
0 commit comments