LEFT | RIGHT |
(no file at all) | |
1 <!--{ | 1 <!--{ |
2 "Title": "How to Write Go Code" | 2 "Title": "How to Write Go Code" |
3 }--> | 3 }--> |
4 | 4 |
5 <h2 id="Introduction">Introduction</h2> | 5 <h2 id="Introduction">Introduction</h2> |
6 | 6 |
7 <p> | 7 <p> |
8 This document explains how to write a new package | 8 This document explains how to write a new package |
9 and how to test code. | 9 and how to test code. |
10 It assumes you have installed Go using the | 10 It assumes you have installed Go using the |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 <p>For example, consider the package <code>foo</code> that consists of four | 316 <p>For example, consider the package <code>foo</code> that consists of four |
317 files:</p> | 317 files:</p> |
318 | 318 |
319 <pre> | 319 <pre> |
320 foo.go | 320 foo.go |
321 foo_386.go | 321 foo_386.go |
322 foo_amd64.go | 322 foo_amd64.go |
323 foo_arm.go | 323 foo_arm.go |
324 </pre> | 324 </pre> |
325 | 325 |
326 describes a package that builds on | 326 <p>describes a package that builds on |
327 different architectures by parameterizing the file name with | 327 different architectures by parameterizing the file name with |
328 <code>$GOARCH</code>.</p> | 328 <code>$GOARCH</code>.</p> |
329 | 329 |
330 <p>The general code goes in <code>foo.go</code>, while architecture-specific | 330 <p>The general code goes in <code>foo.go</code>, while architecture-specific |
331 code goes in <code>foo_386.go</code>, <code>foo_amd64.go</code>, and | 331 code goes in <code>foo_386.go</code>, <code>foo_amd64.go</code>, and |
332 <code>foo_arm.go</code>.</p> | 332 <code>foo_arm.go</code>.</p> |
333 | 333 |
334 <p>If you follow these conventional parameterizations, tools such as the <a | 334 <p>If you follow these conventional parameterizations, tools such as the <a |
335 href="/cmd/go/"><code>go</code> tool</a> will work seamlessly with your | 335 href="/cmd/go/"><code>go</code> tool</a> will work seamlessly with your |
336 package:</p> | 336 package:</p> |
337 | 337 |
338 <pre> | 338 <pre> |
339 foo_$GOOS.go | 339 foo_$GOOS.go |
340 foo_$GOARCH.go | 340 foo_$GOARCH.go |
341 foo_$GOOS_$GOARCH.go | 341 foo_$GOOS_$GOARCH.go |
342 </pre> | 342 </pre> |
343 | 343 |
344 <p>The same holds for <code>.s</code> (assembly) and <code>.c</code> files.</p> | 344 <p>The same holds for <code>.s</code> (assembly) and <code>.c</code> files.</p> |
LEFT | RIGHT |