Fix formatting after import
diff --git a/Books.md b/Books.md
index b81947e..792df0e 100644
--- a/Books.md
+++ b/Books.md
@@ -39,6 +39,11 @@
* ISBN: ---
* References: [site](http://jan.newmarch.name/go/)
+ * **Go: Up and Running**
+ * Author: Alan Harris
+ * Publication Date: April 2015 (est.)
+ * ISBN: 978-1-4493-7025-1
+
* **Go In Action**
* Authors: Brian Ketelsen, Erik St. Martin, and William Kennedy
* Publication Date: Summer 2015 (est.)
diff --git a/BoundingResourceUse.md b/BoundingResourceUse.md
index dc78332..a49908d 100644
--- a/BoundingResourceUse.md
+++ b/BoundingResourceUse.md
@@ -1,25 +1,27 @@
# Bounding resource use
To bound a program's use of a limited resource, like memory, have goroutines synchronize their use of that resource using a buffered channel (i.e., use the channel as a semaphore):
+
```
const (
- AvailableMemory = 10 << 20 // 10 MB
- AverageMemoryPerRequest = 10 << 10 // 10 KB
- MaxOutstanding = AvailableMemory / AverageMemoryPerRequest
+ AvailableMemory = 10 << 20 // 10 MB
+ AverageMemoryPerRequest = 10 << 10 // 10 KB
+ MaxOutstanding = AvailableMemory / AverageMemoryPerRequest
)
+
var sem = make(chan int, MaxOutstanding)
func Serve(queue chan *Request) {
- for {
- sem <- 1 // Block until there's capacity to process a request.
- req := <-queue
- go handle(req) // Don't wait for handle to finish.
- }
+ for {
+ sem <- 1 // Block until there's capacity to process a request.
+ req := <-queue
+ go handle(req) // Don't wait for handle to finish.
+ }
}
func handle(r *Request) {
- process(r) // May take a long time & use a lot of memory or CPU
- <-sem // Done; enable next request to run.
+ process(r) // May take a long time & use a lot of memory or CPU
+ <-sem // Done; enable next request to run.
}
```
diff --git a/ChromeOS.md b/ChromeOS.md
index d885722..daf26b2 100644
--- a/ChromeOS.md
+++ b/ChromeOS.md
@@ -5,8 +5,13 @@
Your chrome book must be in developer mode for this to work. Also please note this has only been tested on a 64gb LTE Pixel however it should work on other chrome books
# Install Go
-First download the latest version of Go for Linux-amd64 from the [Go Downloads page](https://code.google.com/p/go/downloads/list) after that open a shell by hitting (Crtl+alt+t) and typing in "shell" then hit enter. Then extract it using the following command.```
-sudo tar -C /usr/local -xzf ~/Downloads/FILENAMEHERE``` Go should now be installed you can test this by typing "/usr/local/go/bin/go" if it installed you should see the go help prompt. Congrats Go is now installed however you will not be able to run anything because chrome mounts partitions with noexec. The following will guide you through remounting your home folder, and setting up paths that are persistent across reboots, and shell sessions.
+First download the latest version of Go for Linux-amd64 from the [Go Downloads page](https://code.google.com/p/go/downloads/list) after that open a shell by hitting (Crtl+alt+t) and typing in "shell" then hit enter. Then extract it using the following command.
+
+```
+sudo tar -C /usr/local -xzf ~/Downloads/FILENAMEHERE
+```
+
+Go should now be installed you can test this by typing "/usr/local/go/bin/go" if it installed you should see the go help prompt. Congrats Go is now installed however you will not be able to run anything because chrome mounts partitions with noexec. The following will guide you through remounting your home folder, and setting up paths that are persistent across reboots, and shell sessions.
# Create a Workspace
To keep this simple just create a folder called "gocode" in your downloads folder. Also create a folder called "src" inside.
@@ -14,7 +19,6 @@
# Set Paths & Exec
Either type the following into your shell each session or if you want it to be persistent between sessions add it to your "~/.bashrc" file. The last line remounts your user folder so that you can run your go code other wise you would get permission errors.
```
-
export PATH=$PATH:/usr/local/go/bin
export GOPATH=~/Downloads/gocode
export PATH=$PATH:$GOPATH/bin
@@ -24,11 +28,12 @@
# Test If It Worked
First add a "hello" folder inside of your "gocode/src" folder. After that create a file in your "gocode/src/hello" folder called "hello.go" with the following in it. Then run "go install hello" then "hello" and you should see "Hello, chrome os" in the console.
-```
+```go
package main
import "fmt"
func main() {
-fmt.Printf("Hello, chrome os\n")
-}```
\ No newline at end of file
+ fmt.Printf("Hello, chrome os\n")
+}
+```
\ No newline at end of file
diff --git a/CodeReviewComments.md b/CodeReviewComments.md
index 49c2344..24b609a 100644
--- a/CodeReviewComments.md
+++ b/CodeReviewComments.md
@@ -12,9 +12,9 @@
## gofmt
-Run [gofmt](http://golang.org/cmd/gofmt/) on your code to automatically fix the majority of mechanical style issues. Almost all Go code in the wild uses ` gofmt `. The rest of this document addresses non-mechanical style points.
+Run [gofmt](http://golang.org/cmd/gofmt/) on your code to automatically fix the majority of mechanical style issues. Almost all Go code in the wild uses `gofmt`. The rest of this document addresses non-mechanical style points.
-An alternative is to use [goimports](https://godoc.org/code.google.com/p/go.tools/cmd/goimports), a superset of ` gofmt ` which additionally adds (and removes) import lines as necessary.
+An alternative is to use [goimports](https://godoc.org/code.google.com/p/go.tools/cmd/goimports), a superset of `gofmt` which additionally adds (and removes) import lines as necessary.
## Comment Sentences
@@ -44,7 +44,7 @@
## Handle Errors
-See http://golang.org/doc/effective_go.html#errors. Do not discard errors using ` _ ` variables. If a function returns an error, check it to make sure the function succeeded. Handle the error, return it, or, in truly exceptional situations, panic.
+See http://golang.org/doc/effective_go.html#errors. Do not discard errors using `_` variables. If a function returns an error, check it to make sure the function succeeded. Handle the error, return it, or, in truly exceptional situations, panic.
## Imports
@@ -54,15 +54,15 @@
package main
import (
- "fmt"
- "hash/adler32"
- "os"
+ "fmt"
+ "hash/adler32"
+ "os"
- "appengine/user"
- "appengine/foo"
+ "appengine/foo"
+ "appengine/user"
- "code.google.com/p/x/y"
- "github.com/foo/bar"
+ "code.google.com/p/x/y"
+ "github.com/foo/bar"
)
```
@@ -76,8 +76,8 @@
package foo_test
import (
- . "foo"
- "bar/testutil" // also imports "foo"
+ "bar/testutil" // also imports "foo"
+ . "foo"
)
```
@@ -89,9 +89,9 @@
```
if err != nil {
- // error handling
+ // error handling
} else {
- // normal code
+ // normal code
}
```
@@ -99,8 +99,8 @@
```
if err != nil {
- // error handling
- return // or continue, etc.
+ // error handling
+ return // or continue, etc.
}
// normal code
```
@@ -109,10 +109,10 @@
```
if x, err := f(); err != nil {
- // error handling
- return
+ // error handling
+ return
} else {
- // use x
+ // use x
}
```
@@ -121,8 +121,8 @@
```
x, err := f()
if err != nil {
- // error handling
- return
+ // error handling
+ return
}
// use x
```
@@ -143,7 +143,7 @@
## Mixed Caps
-See http://golang.org/doc/effective_go.html#mixed-caps. This applies even when it breaks conventions in other languages. For example an unexported constant is ` maxLength ` not ` MaxLength ` or ` MAX_LENGTH `.
+See http://golang.org/doc/effective_go.html#mixed-caps. This applies even when it breaks conventions in other languages. For example an unexported constant is `maxLength` not `MaxLength` or `MAX_LENGTH`.
## Named Result Parameters
@@ -162,14 +162,14 @@
On the other hand, if a function returns two or three parameters of the same type, or if the meaning of a result isn't clear from context, adding names may be useful. For example:
```go
-
-func (f *Foo) Location() (float64, float64, error)```
+func (f *Foo) Location() (float64, float64, error)
+```
is less clear than
```go
-
// Location returns f's latitude and longitude.
// Negative values mean south and west, respectively.
-func (f *Foo) Location() (lat, long float64, err error)```
+func (f *Foo) Location() (lat, long float64, err error)
+```
Naked returns are okay if the function is a handful of lines. Once it's a medium-sized function, be explicit with your return values. Corollary: it's not worth it to name result parameters just because it enables you to use naked returns. Clarity of docs is always more important than saving a line or two in your function.
@@ -205,7 +205,7 @@
## Pass Values
-Don't pass pointers as function arguments just to save a few bytes. If a function refers to its argument ` x ` only as ` *x ` throughout, then the argument shouldn't be a pointer. Common instances of this include passing a pointer to a string (` *string `) or a pointer to an interface value (` *io.Reader `). In both cases the value itself is a fixed size and can be passed directly. This advice does not apply to large structs, or even small structs that might grow.
+Don't pass pointers as function arguments just to save a few bytes. If a function refers to its argument `x` only as `*x` throughout, then the argument shouldn't be a pointer. Common instances of this include passing a pointer to a string (`*string`) or a pointer to an interface value (`*io.Reader`). In both cases the value itself is a fixed size and can be passed directly. This advice does not apply to large structs, or even small structs that might grow.
## Receiver Names
@@ -230,9 +230,9 @@
Tests should fail with helpful messages saying what was wrong, with what inputs, what was actually got, and what was expected. It may be tempting to write a bunch of assertFoo helpers, but be sure your helpers produce useful error messages. Assume that the person debugging your failing test is not you, and is not your team. A typical Go test fails like:
```
- if got != tt.want {
- t.Errorf("Foo(%q) = %d; want %d", tt.in, got, tt.want) // or Fatalf, if test can't test anything more past this point
- }
+if got != tt.want {
+ t.Errorf("Foo(%q) = %d; want %d", tt.in, got, tt.want) // or Fatalf, if test can't test anything more past this point
+}
```
Note that the order here is actual != expected, and the message uses that order too. Some test frameworks encourage writing these backwards: 0 != x, "expected 0, got x", and so on. Go does not.
@@ -242,8 +242,8 @@
Another common technique to disambiguate failing tests when using a test helper with different input is to wrap each caller with a different TestFoo function, so the test fails with that name:
```
- func TestSingleValue(t *testing.T) { testHelper(t, []int{80}) }
- func TestNoValues(t *testing.T) { testHelper(t, []int{}) }
+func TestSingleValue(t *testing.T) { testHelper(t, []int{80}) }
+func TestNoValues(t *testing.T) { testHelper(t, []int{}) }
```
In any case, the onus is on you to fail with a helpful message to whoever's debugging your code in the future.
@@ -252,4 +252,4 @@
Variable names in Go should be short rather than long. This is especially true for local variables with limited scope. Prefer c to lineCount. Prefer i to sliceIndex.
-The basic rule: the further from its declaration that a name is used, the more descriptive the name must be. For a method receiver, one or two letters is sufficient. Common variables such as loop indices and readers can be a single letter (` i `, ` r `). More unusual things and global variables need more descriptive names.
\ No newline at end of file
+The basic rule: the further from its declaration that a name is used, the more descriptive the name must be. For a method receiver, one or two letters is sufficient. Common variables such as loop indices and readers can be a single letter (`i`, `r`). More unusual things and global variables need more descriptive names.
\ No newline at end of file
diff --git a/CommonMistakes.md b/CommonMistakes.md
index 076da07..03a1be8 100644
--- a/CommonMistakes.md
+++ b/CommonMistakes.md
@@ -11,9 +11,9 @@
When iterating in Go, one might also be tempted to use a closure and goroutine to process data in parallel. For example, if you wanted to process values coming in from a channel in their own goroutines, you might write the following code:
```
for val := range values {
- go func() {
- fmt.Println(val)
- }()
+ go func() {
+ fmt.Println(val)
+ }()
}
```
@@ -24,9 +24,9 @@
The proper way to write that loop is:
```
for val := range values {
- go func(val interface{}) {
- fmt.Println(val)
- }(val)
+ go func(val interface{}) {
+ fmt.Println(val)
+ }(val)
}
```
@@ -36,10 +36,10 @@
```
for i := range valslice {
- val := valslice[i]
- go func() {
- fmt.Println(val)
- }()
+ val := valslice[i]
+ go func() {
+ fmt.Println(val)
+ }()
}
```
@@ -47,9 +47,9 @@
```
for i := 1; i <= 10; i++ {
- func() {
- fmt.Println(i)
- }()
+ func() {
+ fmt.Println(i)
+ }()
}
```
diff --git a/Courses.md b/Courses.md
index 4a3f1bb..27eaa5d 100644
--- a/Courses.md
+++ b/Courses.md
@@ -1,6 +1,6 @@
# Introduction
-Go is a great langage for CS majors. This page presents some university courses that uses Go.
+Go is a great langage for CS majors. This page presents some university courses that use Go.
# Language
diff --git a/DashboardBuilders.md b/DashboardBuilders.md
index ff74789..5bc8a64 100644
--- a/DashboardBuilders.md
+++ b/DashboardBuilders.md
@@ -24,6 +24,7 @@
## Legacy Builders
These builders are configured and run manually. The goal is to migrate as many as possible over to the new system.
+
| **title** | **description** | **owner** | **notes** |
|:----------|:----------------|:----------|:----------|
| darwin-amd64 | 2011 Mac Mini, 2.4Ghz Core i5 | adg | Mac OS X 10.6 (10K549) |
diff --git a/Errors.md b/Errors.md
index 6436d9e..a08b7bd 100644
--- a/Errors.md
+++ b/Errors.md
@@ -1,12 +1,12 @@
# Errors
-Errors are indicated by returning an ` error ` as an additional return value from a function. A ` nil ` value means that there was no error.
+Errors are indicated by returning an `error` as an additional return value from a function. A `nil` value means that there was no error.
-` error `s can be turned into strings by calling ` Error `, their only method. You can create an error from a string by calling ` errors.New `:
+` error `s can be turned into strings by calling `Error`, their only method. You can create an error from a string by calling `errors.New`:
```
if failure {
- return errors.New("inverse tachyon pulse failed")
+ return errors.New("inverse tachyon pulse failed")
}
```
@@ -15,38 +15,38 @@
```
err := TryInverseTachyonPulse()
if err != nil {
- fmt.Printf("failed to solve problem: %s\n", err)
+ fmt.Printf("failed to solve problem: %s\n", err)
}
```
If you expect calling code to be able to handle an error, you can distinguish classes of errors either by returning special values, or new types. You only need to distinguish differences that the calling code could be expected to handle in this way as the string allows one to communicate the details of the error.
-` io.EOF ` is a special value that signals the end of a stream. You can compare error values directly against io.EOF.
+`io.EOF` is a special value that signals the end of a stream. You can compare error values directly against io.EOF.
If you want to carry extra data with the error, you can use a new type:
```
type ParseError struct {
- Line, Col int
+ Line, Col int
}
func (p ParseError) Error() string {
- return fmt.Sprintf("parse error on line %d, column %d", p.Line, p.Col)
+ return fmt.Sprintf("parse error on line %d, column %d", p.Line, p.Col)
}
```
-Calling code would test for a special type of ` error ` by using a type switch:
+Calling code would test for a special type of `error` by using a type switch:
```
switch err := err.(type) {
case ParseError:
- PrintParseError(err)
+ PrintParseError(err)
}
```
## Naming
-Error types end in ` "Error" ` and error variables start with ` "Err" `:
+Error types end in `"Error"` and error variables start with `"Err"`:
```
package somepkg
@@ -78,5 +78,5 @@
## References
* Errors (specification): http://golang.org/ref/spec#Errors
- * Package ` errors `: http://golang.org/pkg/errors/
+ * Package `errors`: http://golang.org/pkg/errors/
* Type switches: http://golang.org/doc/go_spec.html#TypeSwitchStmt
\ No newline at end of file
diff --git a/FreeBSD.md b/FreeBSD.md
index 945c498..66cf269 100644
--- a/FreeBSD.md
+++ b/FreeBSD.md
@@ -3,12 +3,11 @@
Required:
* FreeBSD amd64, 386: 8.0 or above
-
* FreeBSD arm: 10.0 or above
* See http://golang.org/issue/7849 for further information.
| **Kernel version** | **Min. version** | **Max. version**|
-|:-------------------|:-----------------|:|
+|:-------------------|:-----------------|:----------------|
| 11-CURRENT | go1.3 w/ issue 7849 (on Google Code) | go1.4 w/ issue 7849 (on Google Code) |
| 10-STABLE | go1.3 | go1.4 |
| 9-STABLE | go1 | go1.4 |
diff --git a/GcToolchainTricks.md b/GcToolchainTricks.md
index b025c98..fe2faa3 100644
--- a/GcToolchainTricks.md
+++ b/GcToolchainTricks.md
@@ -74,6 +74,7 @@
```
/* data.go */
package bindata
+
func getDataSlices() ([]byte, []byte) // defined in slice.c
var A, B = getDataSlices()
diff --git a/GccgoCrossCompilation.md b/GccgoCrossCompilation.md
index 1afee36..7e10bfa 100644
--- a/GccgoCrossCompilation.md
+++ b/GccgoCrossCompilation.md
@@ -69,7 +69,7 @@
### Gotchas
-If you haven't compiled a shared object of the go library, _libgo_, for your target you might want to compile your Go programs statically, just like _gc_ does, to include all what is needed to run your program. Do this by adding the _-static_ switch to gccgo. If you're unsure how your produced ELF file is liked, inspect it with _readelf -d ` <elf `>_ or _objdump -T ` <elf `>_.
+If you haven't compiled a shared object of the go library, _libgo_, for your target you might want to compile your Go programs statically, just like _gc_ does, to include all what is needed to run your program. Do this by adding the _-static_ switch to gccgo. If you're unsure how your produced ELF file is liked, inspect it with _readelf -d `<elf>`_ or _objdump -T `<elf>`_.
## Build a cross-gccgo aware version of the Go tool
diff --git a/GithubCodeLayout.md b/GithubCodeLayout.md
index 1f2cf29..d2dfd5f 100644
--- a/GithubCodeLayout.md
+++ b/GithubCodeLayout.md
@@ -44,7 +44,6 @@
Let's assume we are starting from scratch. Initialize the two new repositories on Github, using the "Initialize this repository with a README" option so your repos can be cloned immediately. Then setup the project like this:
```sh
-
cd ~/workspace # Standard location for Eclipse workspace
mkdir mygo # Create your Go workspace
export GOPATH=~/workspace/mygo # GOPATH = Go workspace
@@ -63,8 +62,9 @@
package useless
func Foobar() string {
-return "Foobar!"
-}```
+ return "Foobar!"
+}
+```
# Applications
@@ -77,18 +77,19 @@
package main
import (
-"net/http"
+ "net/http"
-"code.google.com/p/go.net/websocket"
-"github.com/jmcvetta/useless"
+ "code.google.com/p/go.net/websocket"
+ "github.com/jmcvetta/useless"
)
func main() {
-http.Handle("/useless", websocket.Handler(func(ws *websocket.Conn) {
-ws.Write([]byte(useless.Foobar()))
-}))
-http.ListenAndServe(":3000", nil)
-}```
+ http.Handle("/useless", websocket.Handler(func(ws *websocket.Conn) {
+ ws.Write([]byte(useless.Foobar()))
+ }))
+ http.ListenAndServe(":3000", nil)
+}
+```
# Dependencies
diff --git a/Go1point1Gotchas.md b/Go1point1Gotchas.md
index e4a12f5..c210f3c 100644
--- a/Go1point1Gotchas.md
+++ b/Go1point1Gotchas.md
@@ -11,26 +11,26 @@
For example, take this struct with an embedded ` *bytes.Buffer ` field:
```
- type S struct {
- *bytes.Buffer
- }
+type S struct {
+ *bytes.Buffer
+}
```
In Go 1.0 the compiler would (incorrectly) accept this struct literal:
```
- s := S{
- bytes.Buffer: new(bytes.Buffer),
- }
+s := S{
+ bytes.Buffer: new(bytes.Buffer),
+}
```
Under Go 1.1 the compiler rejects this.
Instead you should use the field name without the package qualifier:
```
- s := S{
- Buffer: new(bytes.Buffer),
- }
+s := S{
+ Buffer: new(bytes.Buffer),
+}
```
## Initialization loop
@@ -40,26 +40,26 @@
For instance, the following code compiled under Go 1.0.
```
- var funcVar = fn
+var funcVar = fn
- func fn() {
- funcVar()
- }
+func fn() {
+ funcVar()
+}
```
Such code must now use an ` init ` function for the variable assignment to avoid
the initialization loop.
```
- var funcVar func()
+var funcVar func()
- func fn() {
- funcVar()
- }
+func fn() {
+ funcVar()
+}
- func init() {
- funcVar = fn
- }
+func init() {
+ funcVar = fn
+}
```
In particular, this affects users of App Engine's [delay package](https://developers.google.com/appengine/docs/go/taskqueue/delay).
@@ -70,12 +70,12 @@
Go 1.0 permitted fallthrough in the final case of a switch statement:
```
- switch {
- case false:
- fallthrough // fall through to 'true' case
- case true:
- fallthrough // fall through to... nowhere?
- }
+switch {
+case false:
+ fallthrough // fall through to 'true' case
+case true:
+ fallthrough // fall through to... nowhere?
+}
```
A language change affecting [return requirements](http://golang.org/doc/go1.1#return) led us to make the superfluous fallthrough illegal.
@@ -88,7 +88,7 @@
A compiler bug permitted function type declarations with parameters and return values of the same name. This would compile under Go 1.0:
```
- type T func(a int) (a int)
+type T func(a int) (a int)
```
Under Go 1.1, the compiler gives an error:
diff --git a/GoArm.md b/GoArm.md
index 6549015..5989cb2 100644
--- a/GoArm.md
+++ b/GoArm.md
@@ -308,7 +308,6 @@
| Power Switch | To power cycle the board ?|
```
-
root@bpi01:/data/go13/src# cat ./buildgo.bash
#!/bin/bash
# use 1 CPU to avoid out of memory compilation issue.
diff --git a/GoForCPPProgrammers.md b/GoForCPPProgrammers.md
index fa9bd8d..b48597c 100644
--- a/GoForCPPProgrammers.md
+++ b/GoForCPPProgrammers.md
@@ -96,8 +96,8 @@
```
var (
- i int
- m float64
+ i int
+ m float64
)
```
@@ -128,19 +128,19 @@
` := ` .
```
-v1 := v2 // C++11: auto v1 = v2;
+v1 := v2 // C++11: auto v1 = v2;
```
This is equivalent to
```
-var v1 = v2 // C++11: auto v1 = v2;
+var v1 = v2 // C++11: auto v1 = v2;
```
Go permits multiple assignments, which are done in parallel. That is, first all of the values on the right-hand side are computed, and then these values are assigned to the variables on the left-hand side.
```
-i, j = j, i // Swap i and j.
+i, j = j, i // Swap i and j.
```
Functions may have multiple return values, indicated by a list in
@@ -218,9 +218,9 @@
are used in the same way.
```
-type myStruct struct { i int }
-var v9 myStruct // v9 has structure type
-var p9 *myStruct // p9 is a pointer to a structure
+type myStruct struct{ i int }
+var v9 myStruct // v9 has structure type
+var p9 *myStruct // p9 is a pointer to a structure
f(v9.i, p9.i)
```
@@ -255,9 +255,9 @@
```
switch i {
-case 0: // empty case body
+case 0: // empty case body
case 1:
- f() // f is not called when i == 0!
+ f() // f is not called when i == 0!
}
```
@@ -266,7 +266,7 @@
```
switch i {
case 0, 1:
- f() // f is called if i == 0 || i == 1.
+ f() // f is called if i == 0 || i == 1.
}
```
@@ -279,11 +279,11 @@
```
switch {
case i < 0:
- f1()
+ f1()
case i == 0:
- f2()
+ f2()
case i > 0:
- f3()
+ f3()
}
```
@@ -291,7 +291,7 @@
```
fd := open("filename")
-defer close(fd) // fd will be closed when this function returns.
+defer close(fd) // fd will be closed when this function returns.
```
<h2>Operators</h2>
@@ -339,7 +339,7 @@
```
var a uint
-f(a + 1) // untyped numeric constant "1" becomes typed as uint
+f(a + 1) // untyped numeric constant "1" becomes typed as uint
```
The language does not impose any limits on the size of an untyped
@@ -359,9 +359,9 @@
```
const (
- red = iota // red == 0
- blue // blue == 1
- green // green == 2
+ red = iota // red == 0
+ blue // blue == 1
+ green // green == 2
)
```
@@ -393,7 +393,7 @@
var pos position = 218.0
var vel velocity = -9.8
-pos += vel // INVALID: mismatched types position and velocity
+pos += vel // INVALID: mismatched types position and velocity
// pos += position(vel) // Valid
```
@@ -529,7 +529,8 @@
the ` this ` pointer in a C++ class method.
```
-type myType struct { i int }
+type myType struct{ i int }
+
func (p *myType) Get() int { return p.i }
```
@@ -545,9 +546,12 @@
```
type myInteger int
+
func (p myInteger) Get() int { return int(p) } // Conversion required.
-func f(i int) { }
+func f(i int) {}
+
var v myInteger
+
// f(v) is invalid.
// f(int(v)) is valid; int(v) has no defined methods.
```
@@ -589,7 +593,11 @@
class.
```
-type myChildType struct { myType; j int }
+type myChildType struct {
+ myType
+ j int
+}
+
func (p *myChildType) Get() int { p.j++; return p.myType.Get() }
```
@@ -629,8 +637,9 @@
type myPrintInterface interface {
Print()
}
+
func f3(x myInterface) {
- x.(myPrintInterface).Print() // type assertion to myPrintInterface
+ x.(myPrintInterface).Print() // type assertion to myPrintInterface
}
```
@@ -644,7 +653,7 @@
manipulating values of the minimal interface.
```
-type Any interface { }
+type Any interface{}
```
Containers may be written in terms of ` Any `, but the caller
@@ -800,9 +809,11 @@
var g int
go func(i int) {
s := 0
- for j := 0; j < i; j++ { s += j }
+ for j := 0; j < i; j++ {
+ s += j
+ }
g = s
-}(1000) // Passes argument 1000 to the function literal.
+}(1000) // Passes argument 1000 to the function literal.
```
Like C++11, but unlike prior versions of C++, Go defines a
@@ -857,7 +868,7 @@
```
func f4(ch chan<- Cmd2) int {
myCh := make(chan int)
- c := Cmd2{ true, 0, myCh } // Composite literal syntax.
+ c := Cmd2{true, 0, myCh} // Composite literal syntax.
ch <- c
return <-myCh
}
diff --git a/GoVsGenerics.md b/GoVsGenerics.md
index 4f5fe8f..70be67f 100644
--- a/GoVsGenerics.md
+++ b/GoVsGenerics.md
@@ -19,15 +19,15 @@
- map() in Python: **map(lambda x:x\*2, range(100))**:
```
- func Map(f interface{}, v interface{}) interface{} {
- // Reflection to solve f and v types
- }
+func Map(f interface{}, v interface{}) interface{} {
+ // Reflection to solve f and v types
+}
```
The reflect solution performance is really bad
- Polymorphic functions that operate on built-in generic types.
```
- func KeyIntersection(a map[T1]T2, b map[T1]T2) map[T1]T2 {}
+func KeyIntersection(a map[T1]T2, b map[T1]T2) map[T1]T2 {}
```
- Containers that must store non-interface values. (Various
diff --git a/HttpStaticFiles.md b/HttpStaticFiles.md
index be8db0e..f8772bd 100644
--- a/HttpStaticFiles.md
+++ b/HttpStaticFiles.md
@@ -9,7 +9,9 @@
```
package main
+
import "net/http"
+
func main() {
panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}
diff --git a/InterfaceSlice.md b/InterfaceSlice.md
index 4acd015..04ae3f3 100644
--- a/InterfaceSlice.md
+++ b/InterfaceSlice.md
@@ -2,8 +2,8 @@
Given that you can assign a variable of any type to an ` interface{} `, often people will try code like the following.
```
- var dataSlice []int = foo()
- var interfaceSlice []interface{} = dataSlice
+var dataSlice []int = foo()
+var interfaceSlice []interface{} = dataSlice
```
This gets the error
```
@@ -34,9 +34,9 @@
If you really want a ` []interface{} ` because you'll be doing indexing before converting back, or you are using a particular interface type and you want to use its methods, you will have to make a copy of the slice.
```
- var dataSlice []int = foo()
- var interfaceSlice []interface{} = make([]interface{}, len(dataSlice))
- for i, d := range dataSlice {
- interfaceSlice[i] = d
- }
+var dataSlice []int = foo()
+var interfaceSlice []interface{} = make([]interface{}, len(dataSlice))
+for i, d := range dataSlice {
+ interfaceSlice[i] = d
+}
```
\ No newline at end of file
diff --git a/Iota.md b/Iota.md
index 6b4f1b4..5084f74 100644
--- a/Iota.md
+++ b/Iota.md
@@ -18,15 +18,16 @@
```
type ByteSize float64
+
const (
- _ = iota // ignore first value by assigning to blank identifier
- KB ByteSize = 1<<(10*iota)
- MB
- GB
- TB
- PB
- EB
- ZB
- YB
+ _ = iota // ignore first value by assigning to blank identifier
+ KB ByteSize = 1 << (10 * iota)
+ MB
+ GB
+ TB
+ PB
+ EB
+ ZB
+ YB
)
```
\ No newline at end of file
diff --git a/LockOSThread.md b/LockOSThread.md
index bb25131..e120c00 100644
--- a/LockOSThread.md
+++ b/LockOSThread.md
@@ -14,7 +14,7 @@
// Arrange that main.main runs on main thread.
func init() {
- runtime.LockOSThread()
+ runtime.LockOSThread()
}
// Main runs the main SDL service loop.
@@ -22,9 +22,9 @@
// Main does not return. If the binary needs to do other work, it
// must do it in separate goroutines.
func Main() {
- for f = range mainfunc {
- f()
- }
+ for f = range mainfunc {
+ f()
+ }
}
// queue of work to run in main thread.
@@ -32,20 +32,20 @@
// do runs f on the main thread.
func do(f func()) {
- done := make(chan bool, 1)
- mainfunc <- func() {
- f()
- done <- true
- }
- <-done
+ done := make(chan bool, 1)
+ mainfunc <- func() {
+ f()
+ done <- true
+ }
+ <-done
}
```
And then other functions you write in package sdl can be like
```
func Beep() {
- do(func() {
- // whatever must run in main thread
- })
+ do(func() {
+ // whatever must run in main thread
+ })
}
```
\ No newline at end of file
diff --git a/MethodSets.md b/MethodSets.md
index 5feb8da..94bf495 100644
--- a/MethodSets.md
+++ b/MethodSets.md
@@ -22,7 +22,8 @@
```
type List []int
-func (l List) Len() int { return len(l) }
+
+func (l List) Len() int { return len(l) }
func (l *List) Append(val int) { *l = append(*l, val) }
func main() {
@@ -87,12 +88,14 @@
```
type List []int
-func (l List) Len() int { return len(l) }
+
+func (l List) Len() int { return len(l) }
func (l *List) Append(val int) { *l = append(*l, val) }
type Appender interface {
Append(int)
}
+
func CountInto(a Appender, start, end int) {
for i := start; i <= end; i++ {
a.Append(i)
@@ -102,6 +105,7 @@
type Lener interface {
Len() int
}
+
func LongEnough(l Lener) bool {
return l.Len()*10 > 42
}
@@ -119,6 +123,6 @@
CountInto(plst, 1, 10) // VALID: Identical receiver type
if LongEnough(plst) { // VALID: a *List can be dereferenced for the receiver
fmt.Printf(" - plst is long enough")
- }
+ }
}
```
\ No newline at end of file
diff --git a/PackagePublishing.md b/PackagePublishing.md
index 88212b5..c6abd4a 100644
--- a/PackagePublishing.md
+++ b/PackagePublishing.md
@@ -82,7 +82,7 @@
package main
import (
- "flag"
+ "flag"
)
import "codesite.tld/authorName/Go-PublishingExample/epub"
@@ -90,8 +90,8 @@
var dir = flag.String("dir", ".", "Directory to publish")
func main() {
- flag.Parse()
- epub.Publish(*dir)
+ flag.Parse()
+ epub.Publish(*dir)
}
```
diff --git a/PanicAndRecover.md b/PanicAndRecover.md
index e886e03..12c25a3 100644
--- a/PanicAndRecover.md
+++ b/PanicAndRecover.md
@@ -11,68 +11,68 @@
```
// A ParseError indicates an error in converting a word into an integer.
type ParseError struct {
- Index int // The index into the space-separated list of words.
- Word string // The word that generated the parse error.
- Error error // The raw error that precipitated this error, if any.
+ Index int // The index into the space-separated list of words.
+ Word string // The word that generated the parse error.
+ Error error // The raw error that precipitated this error, if any.
}
// String returns a human-readable error message.
func (e *ParseError) String() string {
- return fmt.Sprintf("pkg: error parsing %q as int", e.Word)
+ return fmt.Sprintf("pkg: error parsing %q as int", e.Word)
}
// Parse parses the space-separated words in in put as integers.
func Parse(input string) (numbers []int, err error) {
- defer func() {
- if r := recover(); r != nil {
- var ok bool
- err, ok = r.(error)
- if !ok {
- err = fmt.Errorf("pkg: %v", r)
- }
- }
- }()
+ defer func() {
+ if r := recover(); r != nil {
+ var ok bool
+ err, ok = r.(error)
+ if !ok {
+ err = fmt.Errorf("pkg: %v", r)
+ }
+ }
+ }()
- fields := strings.Fields(input)
- numbers = fields2numbers(fields)
- return
+ fields := strings.Fields(input)
+ numbers = fields2numbers(fields)
+ return
}
func fields2numbers(fields []string) (numbers []int) {
- if len(fields) == 0 {
- panic("no words to parse")
- }
- for idx, field := range fields {
- num, err := strconv.Atoi(field)
- if err != nil {
- panic(&ParseError{idx, field, err})
- }
- numbers = append(numbers, num)
- }
- return
+ if len(fields) == 0 {
+ panic("no words to parse")
+ }
+ for idx, field := range fields {
+ num, err := strconv.Atoi(field)
+ if err != nil {
+ panic(&ParseError{idx, field, err})
+ }
+ numbers = append(numbers, num)
+ }
+ return
}
```
To demonstrate the behavior, consider the following main function:
```
func main() {
- var examples = []string{
- "1 2 3 4 5",
- "100 50 25 12.5 6.25",
- "2 + 2 = 4",
- "1st class",
- "",
- }
+ var examples = []string{
+ "1 2 3 4 5",
+ "100 50 25 12.5 6.25",
+ "2 + 2 = 4",
+ "1st class",
+ "",
+ }
- for _, ex := range examples {
- fmt.Printf("Parsing %q:\n ", ex)
- nums, err := Parse(ex)
- if err != nil {
- fmt.Println(err)
- continue
- }
- fmt.Println(nums)
- }
+ for _, ex := range examples {
+ fmt.Printf("Parsing %q:\n ", ex)
+ nums, err := Parse(ex)
+ if err != nil {
+ fmt.Println(err)
+ continue
+ }
+ fmt.Println(nums)
+ }
}
```
diff --git a/Projects.md b/Projects.md
index e5204ff..83cd6ac 100644
--- a/Projects.md
+++ b/Projects.md
@@ -29,6 +29,7 @@
## Build Tools
* [colorgo](https://github.com/songgao/colorgo) - Colorize go build output
+ * [dogo](https://github.com/liudng/dogo) - Monitoring changes in the source file and automatically compile and run (restart)
* [fileembed-go](https://bitbucket.org/rj/fileembed-go/) - This is a command-line utility to take a number of source files, and embed them into a Go package
* [gb](http://github.com/skelterjohn/go-gb) - A(nother) build tool for go, with an emphasis on multi-package projects
* [GG](http://www.manatlan.com/page/gg) - A build tool for Go in Go
@@ -1092,6 +1093,7 @@
* [OAuth Consumer](https://github.com/mrjones/oauth) - OAuth 1.0 consumer implementation
* [authcookie](https://github.com/dchest/authcookie) - Package authcookie implements creation and verification of signed authentication cookies.
* [totp](https://github.com/balasanjay/totp) - Time-Based One-Time Password Algorithm, specified in RFC 6238, works with Google Authenticator
+ * [otp](http://tristanwietsma.github.io/otp/) - HOTP and TOTP library with command line replacement for Google Authenticator
* [dgoogauth](https://github.com/dgryski/dgoogauth) - Go port of Google's Authenticator library for one-time passwords
* [go-http-auth](https://github.com/abbot/go-http-auth) - HTTP Basic and HTTP Digest authentication
* [httpauth](https://github.com/apexskier/httpauth) - HTTP session (cookie) based authentication and authorization
diff --git a/Range.md b/Range.md
index cdd6fc8..49c1c6a 100644
--- a/Range.md
+++ b/Range.md
@@ -10,15 +10,15 @@
```
for k, v := range myMap {
- log.Printf("key=%v, value=%v", k, v)
+ log.Printf("key=%v, value=%v", k, v)
}
for v := range myChannel {
- log.Printf("value=%v", v)
+ log.Printf("value=%v", v)
}
for i, v := range myArray {
- log.Printf("array value at [%d]=%v", i, v)
+ log.Printf("array value at [%d]=%v", i, v)
}
```
@@ -50,7 +50,7 @@
```
items := make([]map[int]int, 10)
for i := range items {
- items[i] = make(map[int]int, 1)
+ items[i] = make(map[int]int, 1)
items[i][1] = 2
}
```
\ No newline at end of file
diff --git a/RateLimiting.md b/RateLimiting.md
index 9067c6d..abbb005 100644
--- a/RateLimiting.md
+++ b/RateLimiting.md
@@ -66,65 +66,63 @@
// }
//
package ratelimit
+
import "time"
type Ratelimiter struct {
+ rate int // conn/sec
+ last time.Time // last time we were polled/asked
- rate int // conn/sec
- last time.Time // last time we were polled/asked
-
- allowance float64
+ allowance float64
}
// Create new rate limiter that limits at rate/sec
func NewRateLimiter(rate int) (*Ratelimiter, error) {
- r := Ratelimiter{rate:rate, last:time.Now()}
+ r := Ratelimiter{rate: rate, last: time.Now()}
- r.allowance = float64(r.rate)
- return &r, nil
+ r.allowance = float64(r.rate)
+ return &r, nil
}
// Return true if the current call exceeds the set rate, false
// otherwise
-func (r* Ratelimiter) Limit() bool {
+func (r *Ratelimiter) Limit() bool {
- // handle cases where rate in config file is unset - defaulting
- // to "0" (unlimited)
- if r.rate == 0 {
- return false
- }
+ // handle cases where rate in config file is unset - defaulting
+ // to "0" (unlimited)
+ if r.rate == 0 {
+ return false
+ }
- rate := float64(r.rate)
- now := time.Now()
- elapsed := now.Sub(r.last)
- r.last = now
- r.allowance += float64(elapsed) * rate
+ rate := float64(r.rate)
+ now := time.Now()
+ elapsed := now.Sub(r.last)
+ r.last = now
+ r.allowance += float64(elapsed) * rate
- // Clamp number of tokens in the bucket. Don't let it get
- // unboundedly large
- if r.allowance > rate {
- r.allowance = rate
- }
+ // Clamp number of tokens in the bucket. Don't let it get
+ // unboundedly large
+ if r.allowance > rate {
+ r.allowance = rate
+ }
- var ret bool
+ var ret bool
- if r.allowance < 1.0 {
- ret = true
- } else {
- r.allowance -= 1.0
- ret = false
- }
+ if r.allowance < 1.0 {
+ ret = true
+ } else {
+ r.allowance -= 1.0
+ ret = false
+ }
- return ret
+ return ret
}
-
```
Using this package is quite easy:
```
-
// rate limit at 100/s
nl = ratelimit.NewRateLimiter(100)
@@ -139,7 +137,6 @@
// .. rate is not exceeded, process as needed
...
}
-
```
[Anti Huimaa](http://stackoverflow.com/questions/667508/whats-a-good-rate-limiting-algorithm) came up with this simple algorithm.
diff --git a/SendingMail.md b/SendingMail.md
index defb5bf..67ee700 100644
--- a/SendingMail.md
+++ b/SendingMail.md
@@ -8,30 +8,30 @@
package main
import (
- "bytes"
- "log"
- "net/smtp"
+ "bytes"
+ "log"
+ "net/smtp"
)
func main() {
- // Connect to the remote SMTP server.
- c, err := smtp.Dial("mail.example.com:25")
- if err != nil {
- log.Fatal(err)
- }
- // Set the sender and recipient.
- c.Mail("sender@example.org")
- c.Rcpt("recipient@example.net")
- // Send the email body.
- wc, err := c.Data()
- if err != nil {
- log.Fatal(err)
- }
- defer wc.Close()
- buf := bytes.NewBufferString("This is the email body.")
- if _, err = buf.WriteTo(wc); err != nil {
- log.Fatal(err)
- }
+ // Connect to the remote SMTP server.
+ c, err := smtp.Dial("mail.example.com:25")
+ if err != nil {
+ log.Fatal(err)
+ }
+ // Set the sender and recipient.
+ c.Mail("sender@example.org")
+ c.Rcpt("recipient@example.net")
+ // Send the email body.
+ wc, err := c.Data()
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer wc.Close()
+ buf := bytes.NewBufferString("This is the email body.")
+ if _, err = buf.WriteTo(wc); err != nil {
+ log.Fatal(err)
+ }
}
```
diff --git a/SignalHandling.md b/SignalHandling.md
index 6434e27..f7fb4d0 100644
--- a/SignalHandling.md
+++ b/SignalHandling.md
@@ -7,22 +7,22 @@
The following code demonstrates a program that waits for an interrupt signal and removes a temporary file when it occurs.
```
- package main
-
- import (
- "io/ioutil"
- "os"
- "os/signal"
- )
-
- func main() {
- f, err := ioutil.TempFile("", "test")
- if err != nil {
- panic(err)
- }
- defer os.Remove(f.Name())
- sig := make(chan os.Signal, 1)
- signal.Notify(sig, os.Interrupt)
- <-sig
- }
+package main
+
+import (
+ "io/ioutil"
+ "os"
+ "os/signal"
+)
+
+func main() {
+ f, err := ioutil.TempFile("", "test")
+ if err != nil {
+ panic(err)
+ }
+ defer os.Remove(f.Name())
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt)
+ <-sig
+}
```
\ No newline at end of file
diff --git a/SliceTricks.md b/SliceTricks.md
index b0f4c6d..9a108c9 100644
--- a/SliceTricks.md
+++ b/SliceTricks.md
@@ -31,8 +31,8 @@
> ` Cut `
```
copy(a[i:], a[j:])
-for k, n := len(a)-j+i, len(a); k < n; k ++ {
- a[k] = nil // or the zero value of T
+for k, n := len(a)-j+i, len(a); k < n; k++ {
+ a[k] = nil // or the zero value of T
} // for k
a = a[:len(a)-j+i]
```
@@ -89,8 +89,8 @@
```
b := a[:0]
for _, x := range a {
- if f(x) {
- b = append(b, x)
- }
+ if f(x) {
+ b = append(b, x)
+ }
}
```
\ No newline at end of file
diff --git a/Switch.md b/Switch.md
index 63adb8f..c6a9de3 100644
--- a/Switch.md
+++ b/Switch.md
@@ -5,20 +5,20 @@
Go's ` switch ` statements are pretty neat. For one thing, you don't need to break at the end of each case.
```
- switch c {
- case '&':
- esc = "&"
- case '\'':
- esc = "'"
- case '<':
- esc = "<"
- case '>':
- esc = ">"
- case '"':
- esc = """
- default:
- panic("unrecognized escape character")
- }
+switch c {
+case '&':
+ esc = "&"
+case '\'':
+ esc = "'"
+case '<':
+ esc = "<"
+case '>':
+ esc = ">"
+case '"':
+ esc = """
+default:
+ panic("unrecognized escape character")
+}
```
[src/pkg/html/escape.go](http://golang.org/src/pkg/html/escape.go#L178)
@@ -28,35 +28,35 @@
Switches work on values of any type.
```
- switch syscall.OS {
- case "windows":
- sd = &sysDir{
- Getenv("SystemRoot") + `\system32\drivers\etc`,
- []string{
- "hosts",
- "networks",
- "protocol",
- "services",
- },
- }
- case "plan9":
- sd = &sysDir{
- "/lib/ndb",
- []string{
- "common",
- "local",
- },
- }
- default:
- sd = &sysDir{
- "/etc",
- []string{
- "group",
- "hosts",
- "passwd",
- },
- }
+switch syscall.OS {
+case "windows":
+ sd = &sysDir{
+ Getenv("SystemRoot") + `\system32\drivers\etc`,
+ []string{
+ "hosts",
+ "networks",
+ "protocol",
+ "services",
+ },
}
+case "plan9":
+ sd = &sysDir{
+ "/lib/ndb",
+ []string{
+ "common",
+ "local",
+ },
+ }
+default:
+ sd = &sysDir{
+ "/etc",
+ []string{
+ "group",
+ "hosts",
+ "passwd",
+ },
+ }
+}
```
## Missing expression
@@ -65,15 +65,15 @@
```
func unhex(c byte) byte {
- switch {
- case '0' <= c && c <= '9':
- return c - '0'
- case 'a' <= c && c <= 'f':
- return c - 'a' + 10
- case 'A' <= c && c <= 'F':
- return c - 'A' + 10
- }
- return 0
+ switch {
+ case '0' <= c && c <= '9':
+ return c - '0'
+ case 'a' <= c && c <= 'f':
+ return c - 'a' + 10
+ case 'A' <= c && c <= 'F':
+ return c - 'A' + 10
+ }
+ return 0
}
```
@@ -86,15 +86,15 @@
argv := strings.Fields(command)
switch argv[0] {
case "echo":
- fmt.Print(argv[1:]...)
+ fmt.Print(argv[1:]...)
case "cat":
- if len(argv) <= 1 {
- fmt.Println("Usage: cat <filename>")
- break
- }
- PrintFile(argv[1])
+ if len(argv) <= 1 {
+ fmt.Println("Usage: cat <filename>")
+ break
+ }
+ PrintFile(argv[1])
default:
- fmt.Println("Unknown command; try 'echo' or 'cat'")
+ fmt.Println("Unknown command; try 'echo' or 'cat'")
}
```
@@ -103,36 +103,36 @@
To fall through to a subsequent case, use the ` fallthrough ` keyword:
```
- // Unpack 4 bytes into uint32 to repack into base 85 5-byte.
- var v uint32
- switch len(src) {
- default:
- v |= uint32(src[3])
- fallthrough
- case 3:
- v |= uint32(src[2]) << 8
- fallthrough
- case 2:
- v |= uint32(src[1]) << 16
- fallthrough
- case 1:
- v |= uint32(src[0]) << 24
- }
+// Unpack 4 bytes into uint32 to repack into base 85 5-byte.
+var v uint32
+switch len(src) {
+default:
+ v |= uint32(src[3])
+ fallthrough
+case 3:
+ v |= uint32(src[2]) << 8
+ fallthrough
+case 2:
+ v |= uint32(src[1]) << 16
+ fallthrough
+case 1:
+ v |= uint32(src[0]) << 24
+}
```
[src/pkg/encoding/ascii85/ascii85.go](http://golang.org/src/pkg/encoding/ascii85/ascii85.go#L43)
The 'fallthrough' must be the last thing in the case; you can't write something like
```
- switch {
- case f():
- if g() {
- fallthrough // Does not work!
- }
- h()
- default:
- error()
+switch {
+case f():
+ if g() {
+ fallthrough // Does not work!
}
+ h()
+default:
+ error()
+}
```
## Multiple cases
diff --git a/WindowsDLLs.md b/WindowsDLLs.md
index 0b15339..e2b798f 100644
--- a/WindowsDLLs.md
+++ b/WindowsDLLs.md
@@ -91,8 +91,6 @@
func init() {
fmt.Print("Starting Up\n")
}
-
-
```
@@ -102,24 +100,23 @@
package main
import (
- "syscall"
- "unsafe"
- "fmt"
+ "fmt"
+ "syscall"
+ "unsafe"
)
func main() {
- var mod = syscall.NewLazyDLL("user32.dll")
- var proc = mod.NewProc("MessageBoxW");
- var MB_YESNOCANCEL = 0x00000003
+ var mod = syscall.NewLazyDLL("user32.dll")
+ var proc = mod.NewProc("MessageBoxW")
+ var MB_YESNOCANCEL = 0x00000003
- ret, _, _ := proc.Call(0,
- uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("Done Title"))),
- uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("This test is Done."))),
- uintptr(MB_YESNOCANCEL));
- fmt.Printf("Return: %d\n", ret)
-
+ ret, _, _ := proc.Call(0,
+ uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("Done Title"))),
+ uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("This test is Done."))),
+ uintptr(MB_YESNOCANCEL))
+ fmt.Printf("Return: %d\n", ret)
+
}
-
```
A third way would be to call into libraries basically by "linking" against the library, using the "[cgo](wiki/cgo)" method (this way works in Linux and Windows):
@@ -130,7 +127,6 @@
import ("C")
...
C.MessageBoxW(...)
-
```
See [cgo](wiki/cgo) for further details.
\ No newline at end of file
diff --git a/cgo.md b/cgo.md
index 7df7b7b..7596343 100644
--- a/cgo.md
+++ b/cgo.md
@@ -82,8 +82,8 @@
package gocallback
import (
- "unsafe"
"fmt"
+ "unsafe"
)
/*