Yet another programming language?
A systems language out of Google designed for
Native compilation
- amd64
- x86
- ARM
- cross-compilation quite easy
Standard profiling and benchmarking tools
Straightforward C-like syntax
Interfaces over inheritance
Canonical maintenance tools
var arg uint32
//...
// explicit casts only allowed in Go
fmt.Printf("arg as int = %d", arg.(int))
// this takes up the amount of space that you'd expect
type TCPPacket struct {
SrcPort uint16
DestPort uint16
Seq uint32
Ack uint32
Flags uint16
Window uint16
Csum uint16
Urgent uint16
Option uint32
Data []byte
}
- Array
- Slice
- Map
- Linked list
- Suffix array
- Ring buffer
- Heap
type Boxofjunk struct {
f *os.File
}
func NewBoxofjunk(file string) (*Boxofjunk, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
b := new(Boxofjunk)
b.f = f
return b, nil
}
// this function is visible to all packages
func PublicFunction(arg string) error {
// ...
}
// this function is only visible within its package
func internalFunction(arg string) error {
// ...
}
Composition over inheritance
- No classes
- No subtype inheritance
- Structural typing only
package io
type Reader interface {
Read(p []byte) (n int, err error)
}
//...
package junkatronics
type MyStuff interface{}
// MyStuff now satisfies the io.Reader interface
func (m *MyStuff) Read(p []byte) (n int, err error) {
//...
}
type MyReadWriter interface {
io.Reader
io.Writer
}
var b []byte
//...
_, err := myReadWriter.Read(b)
listener, err := net.Listen("tcp", ":3456")
if err != nil {
log.Fatalln(err)
}
for {
conn, err := listener.Accept()
if err != nil {
log.Println(err)
continue
}
go handleConnection(conn)
}
func handleSignals(exitChan chan int) {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-signalChan
exitChan <- 1
}()
}
//...
handleSignals(exitChan)
select {
case shutdownNow := <-exitChan:
// handle shutdown
}
// Unbuffered channels
// - sends block until received
syncChan := make(chan int)
syncChan2 := make(chan int, 0)
// Buffered channel
// - sends don't block unless channel is full
asyncChan := make(chan int, 100)
countingSem := make(chan int, MaxInFlight)
func handle(r *Request) {
countingSem <- 1 // Wait for slot to free up
process(r)
<-countingSem // Free up slot for next request to run
}
func Serve(queue chan *Request) {
for {
req := <-queue
go handle(req)
}
}
func DoStuff(path string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
//...
if somethingBadHappened() {
panic("crazy stuff happened!")
}
//...
}
- Compression (tar,zip,bzip2)
- Crypto/TLS
- HTML templating
- Image manipulation
- HTTP
- SMTP
- JSON
- Text parsing and Unicode
- ...and much more!
Unused variables/imports are errors
Tools assume single massive repo