Fix formatting after import

Dave Day 2014-12-10 15:02:18 +11:00
parent 87f483adec
commit 0d6986a1f7
32 changed files with 432 additions and 406 deletions

@ -39,6 +39,11 @@ Sorted by publication date.
* 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.)

@ -1,12 +1,14 @@
# 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
)
var sem = make(chan int, MaxOutstanding)
func Serve(queue chan *Request) {

@ -5,8 +5,13 @@ This tutorial will show you how to install/build/run go on chrome OS. I have tes
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 @@ To keep this simple just create a folder called "gocode" in your downloads folde
# 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 @@ This will allow you to run your go object files in your shell.
# 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")
}```
}
```

@ -58,8 +58,8 @@ import (
"hash/adler32"
"os"
"appengine/user"
"appengine/foo"
"appengine/user"
"code.google.com/p/x/y"
"github.com/foo/bar"
@ -76,8 +76,8 @@ The import . form can be useful in tests that, due to circular dependencies, can
package foo_test
import (
. "foo"
"bar/testutil" // also imports "foo"
. "foo"
)
```
@ -162,14 +162,14 @@ func (n *Node) Parent2() (*Node, error)
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.

@ -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

@ -24,6 +24,7 @@ See http://golang.org/s/builderplan
## 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) |

@ -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 |

@ -74,6 +74,7 @@ And finally, the Go file that uses the embedded slide:
```
/* data.go */
package bindata
func getDataSlices() ([]byte, []byte) // defined in slice.c
var A, B = getDataSlices()

@ -69,7 +69,7 @@ When the cross-compiler is build you should test that it works, both for a simpl
### 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

@ -44,7 +44,6 @@ Both Go and Eclipse use the term "workspace", but they use it to mean something
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
@ -64,7 +63,8 @@ package useless
func Foobar() string {
return "Foobar!"
}```
}
```
# Applications
@ -88,7 +88,8 @@ http.Handle("/useless", websocket.Handler(func(ws *websocket.Conn) {
ws.Write([]byte(useless.Foobar()))
}))
http.ListenAndServe(":3000", nil)
}```
}
```
# Dependencies

@ -308,7 +308,6 @@ _-- Rémy Oudompheng_
| 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.

@ -530,6 +530,7 @@ the ` this ` pointer in a C++ class method.
```
type myType struct{ i int }
func (p *myType) Get() int { return p.i }
```
@ -545,9 +546,12 @@ derived from it. The new type is distinct from the builtin type.
```
type myInteger int
func (p myInteger) Get() int { return int(p) } // Conversion required.
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 @@ An anonymous field may be used to implement something much like a C++ child
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,6 +637,7 @@ not need to be any declared relationship between the two interfaces.
type myPrintInterface interface {
Print()
}
func f3(x myInterface) {
x.(myPrintInterface).Print() // type assertion to myPrintInterface
}
@ -800,7 +809,9 @@ can be useful with the ` go ` statement.
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.
```

@ -9,7 +9,9 @@ This is a complete Go webserver serving static files:
```
package main
import "net/http"
func main() {
panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}

@ -18,6 +18,7 @@ Here's one from Effective Go:
```
type ByteSize float64
const (
_ = iota // ignore first value by assigning to blank identifier
KB ByteSize = 1 << (10 * iota)

@ -22,6 +22,7 @@ In general, when you have a variable of a type, you can pretty much call whateve
```
type List []int
func (l List) Len() int { return len(l) }
func (l *List) Append(val int) { *l = append(*l, val) }
@ -87,12 +88,14 @@ The concrete value stored in an interface is not addressable, in the same way th
```
type List []int
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 @@ func CountInto(a Appender, start, end int) {
type Lener interface {
Len() int
}
func LongEnough(l Lener) bool {
return l.Len()*10 > 42
}

@ -29,6 +29,7 @@ If you find a project in this list that is dead or broken, please either mark it
## 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 @@ See also [SQLDrivers page](https://code.google.com/p/go-wiki/wiki/SQLDrivers).
* [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

@ -66,10 +66,10 @@ Here is a simpler approach that relies on the notion of elapsed time to provide
// }
//
package ratelimit
import "time"
type Ratelimiter struct {
rate int // conn/sec
last time.Time // last time we were polled/asked
@ -118,13 +118,11 @@ func (r* Ratelimiter) Limit() bool {
return ret
}
```
Using this package is quite easy:
```
// rate limit at 100/s
nl = ratelimit.NewRateLimiter(100)
@ -139,7 +137,6 @@ Using this package is quite easy:
// .. 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.

@ -91,8 +91,6 @@ func main() {
func init() {
fmt.Print("Starting Up\n")
}
```
@ -102,24 +100,23 @@ Second way is via syscall.NewProc (etc.) instead of syscall.GetProcAddress. The
package main
import (
"fmt"
"syscall"
"unsafe"
"fmt"
)
func main() {
var mod = syscall.NewLazyDLL("user32.dll")
var proc = mod.NewProc("MessageBoxW");
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));
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 @@ This way would look something like this
import ("C")
...
C.MessageBoxW(...)
```
See [cgo](wiki/cgo) for further details.

2
cgo.md

@ -82,8 +82,8 @@ The following code shows an example of invoking a Go callback from C code. Go pa
package gocallback
import (
"unsafe"
"fmt"
"unsafe"
)
/*