- Concurrency
- Efficiency
- Reliablility
Ryan S. Brown
import (
"fmt"
"github.com/user/project"
)
func main() {
project.Serve(":8000")
}
go fmt
There are no shared libraries. go build
packages in all dependencies
go get github.com/ryansb/lmk
go install github.com/bitly/nsqd/nsqlookupd
package myCoolApplication
import (
anotherpathmodule "vcs.io/repo/path"
"os/path"
)
anotherpathmodule.SomeFunction()
path.SomeValue
func ReadFromBackend(address string) string {
connection := connectTo(address)
return connection.Read()
}
You can use protected values anywhere in your module
type MyConnectionThing struct {
FieldName string
}
func connectTo(address string) MyConnectionThing {
conn := MyConnectionThing{Address: address}
return conn
type Foo interface {
Bar(int) string
Baz() int
}
func (f *Foo) Bar(howmany int) string {
var some = howmany
_ := some
return "hello"
}
import (
"fmt"
"time"
)
func shout(where string, out *chan string) {
for {
time.Sleep(2 * time.Second)
// the <- operator adds a value to a channel
*out <- "hey there from " + where
}
}
func main() {
// a channel can have many writers and many readers
lnk, oma := make(chan string), make(chan string)
// just tell a function to "go" do things in the background
go shout("Lincoln", &lnk)
go shout("Lincoln", &lnk)
go shout("Omaha", &oma)
for {
// channels block if they're out of data
// get whatever channel has data with select
select {
case c := <-lnk :
fmt.Println(c)
case c := <-oma :
fmt.Println(c)
}
}
}
go build; scp myapp webserver:/bin/myapp; echo "that's it. Done."