mirror of
https://github.com/vbatts/talks.git
synced 2025-06-01 17:42:32 +00:00
files from getdown that need to be reconciled
This commit is contained in:
parent
8e251effd9
commit
6943db29ba
36 changed files with 1297 additions and 0 deletions
6
2016/12-intro-to-golang/README.md
Normal file
6
2016/12-intro-to-golang/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
Usage
|
||||
====
|
||||
|
||||
go get golang.org/x/tools/cmd/present
|
||||
present .
|
||||
|
BIN
2016/12-intro-to-golang/cats20.gif
Normal file
BIN
2016/12-intro-to-golang/cats20.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 MiB |
48
2016/12-intro-to-golang/good0.go
Normal file
48
2016/12-intro-to-golang/good0.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for _, arg := range flag.Args() {
|
||||
func() {
|
||||
// START1 OMIT
|
||||
fh, err := os.Open(arg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
gz, err := gzip.NewReader(fh)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer gz.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(gz)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var mine MyStruct
|
||||
err = json.Unmarshal(&mine)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// STOP1 OMIT
|
||||
|
||||
}()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type MyStruct struct {
|
||||
}
|
20
2016/12-intro-to-golang/good1.go
Normal file
20
2016/12-intro-to-golang/good1.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// START1 OMIT
|
||||
// exported
|
||||
type Foo struct {
|
||||
Bar string // exported
|
||||
baz bool // private
|
||||
}
|
||||
|
||||
// private
|
||||
type bif struct {
|
||||
Harf, Buz int64 // doesn't matter
|
||||
}
|
||||
|
||||
// STOP1 OMIT
|
||||
|
||||
func main() {
|
||||
}
|
BIN
2016/12-intro-to-golang/gopher.png
Normal file
BIN
2016/12-intro-to-golang/gopher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
10
2016/12-intro-to-golang/hello.go
Normal file
10
2016/12-intro-to-golang/hello.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// +build ignore
|
||||
|
||||
// START1 OMIT
|
||||
package main
|
||||
|
||||
func main() {
|
||||
println("Howdy y'all")
|
||||
}
|
||||
|
||||
// STOP1 OMIT
|
18
2016/12-intro-to-golang/imports.go
Normal file
18
2016/12-intro-to-golang/imports.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// START1 OMIT
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/foo/bar"
|
||||
)
|
||||
|
||||
// STOP1 OMIT
|
||||
|
||||
func main() {
|
||||
fmt.Println(bar.Baz())
|
||||
_ = os.FileInfo
|
||||
}
|
BIN
2016/12-intro-to-golang/kanye_imma_bookmarklet.png
Normal file
BIN
2016/12-intro-to-golang/kanye_imma_bookmarklet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
33
2016/12-intro-to-golang/pingpong.go
Normal file
33
2016/12-intro-to-golang/pingpong.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
// +build OMIT
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// STARTMAIN1 OMIT
|
||||
type Ball struct{ hits int }
|
||||
|
||||
func main() {
|
||||
table := make(chan *Ball)
|
||||
go player("ping", table)
|
||||
go player("pong", table)
|
||||
|
||||
table <- new(Ball) // game on; toss the ball
|
||||
time.Sleep(1 * time.Second)
|
||||
<-table // game over; grab the ball
|
||||
}
|
||||
|
||||
func player(name string, table chan *Ball) {
|
||||
for {
|
||||
ball := <-table
|
||||
ball.hits++
|
||||
fmt.Println(name, ball.hits)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
table <- ball
|
||||
}
|
||||
}
|
||||
|
||||
// STOPMAIN1 OMIT
|
25
2016/12-intro-to-golang/primitive1.go
Normal file
25
2016/12-intro-to-golang/primitive1.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// START1 OMIT
|
||||
names := []string{
|
||||
"Michael",
|
||||
"Jan",
|
||||
"Sean",
|
||||
"Silvia",
|
||||
}
|
||||
for i, name := range names {
|
||||
fmt.Printf("%q is the %d name\n", name, i)
|
||||
}
|
||||
for i := range names {
|
||||
fmt.Printf("%q is the %d name\n", names[i], i)
|
||||
}
|
||||
for _, name := range names {
|
||||
fmt.Printf("%q is the ... name\n", name)
|
||||
}
|
||||
// STOP1 OMIT
|
||||
}
|
56
2016/12-intro-to-golang/primitive2.go
Normal file
56
2016/12-intro-to-golang/primitive2.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// START1 OMIT
|
||||
infos := map[string]Info{
|
||||
"Michael": Info{
|
||||
City: "Happyville",
|
||||
Status: Open,
|
||||
},
|
||||
"Jan": Info{
|
||||
City: "Confusville",
|
||||
Status: Closed,
|
||||
},
|
||||
"Sean": Info{
|
||||
City: "Septober",
|
||||
Status: Complicated,
|
||||
},
|
||||
"Silvia": Info{
|
||||
City: "Curiousville",
|
||||
Status: Curios,
|
||||
},
|
||||
}
|
||||
for name, info := range infos {
|
||||
fmt.Printf("%q is %s in %q\n", name, info.Status, info.City)
|
||||
}
|
||||
// STOP1 OMIT
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
City string
|
||||
Status Status
|
||||
}
|
||||
type Status int
|
||||
|
||||
var (
|
||||
Open = Status(0)
|
||||
Closed = Status(1)
|
||||
Complicated = Status(2)
|
||||
Curios = Status(3)
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
switch s {
|
||||
case Open:
|
||||
return "open"
|
||||
case Closed:
|
||||
return "closed"
|
||||
case Complicated:
|
||||
return "complicated"
|
||||
}
|
||||
return "hurr"
|
||||
}
|
37
2016/12-intro-to-golang/primitive3.go
Normal file
37
2016/12-intro-to-golang/primitive3.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// START1 OMIT
|
||||
fmt.Println("I've got:")
|
||||
for card := range ReadEmAndWeep() {
|
||||
fmt.Printf(" %s of %s\n", card.Value, card.Suite)
|
||||
}
|
||||
// STOP1 OMIT
|
||||
}
|
||||
|
||||
type Card struct {
|
||||
Suite, Value string
|
||||
}
|
||||
|
||||
// START2 OMIT
|
||||
func ReadEmAndWeep() <-chan Card {
|
||||
c := make(chan Card)
|
||||
go func() {
|
||||
for _, card := range []Card{
|
||||
Card{"Ace", "Jack"},
|
||||
Card{"Ace", "Queen"},
|
||||
Card{"Ace", "King"},
|
||||
Card{"Ace", "Ace"},
|
||||
} {
|
||||
c <- card
|
||||
}
|
||||
close(c)
|
||||
}()
|
||||
return c
|
||||
}
|
||||
|
||||
// STOP2 OMIT
|
BIN
2016/12-intro-to-golang/rainbow.jpg
Normal file
BIN
2016/12-intro-to-golang/rainbow.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
BIN
2016/12-intro-to-golang/revenge-of-the-nerds-o.gif
Normal file
BIN
2016/12-intro-to-golang/revenge-of-the-nerds-o.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 MiB |
8
2016/12-intro-to-golang/tags.go
Normal file
8
2016/12-intro-to-golang/tags.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
// START1 OMIT
|
||||
// +build !windows linux,cgo
|
||||
// STOP1 OMIT
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
262
2016/12-intro-to-golang/talk.slide
Normal file
262
2016/12-intro-to-golang/talk.slide
Normal file
|
@ -0,0 +1,262 @@
|
|||
Intro to Golang
|
||||
05 December 2016
|
||||
|
||||
Vincent Batts
|
||||
Developer
|
||||
@vbatts
|
||||
vbatts@redhat.com
|
||||
https://github.com/vbatts/talks
|
||||
|
||||
* howdy
|
||||
|
||||
$> finger $(whoami)
|
||||
Login: vbatts Name: Vincent Batts
|
||||
Such mail.
|
||||
Plan:
|
||||
right and joyful effort
|
||||
$> id -Gn
|
||||
devel redhat oci containers openshift slackware docker
|
||||
|
||||
: Surview folks familiarity with golang. And with their primary language.
|
||||
|
||||
* golang
|
||||
|
||||
: Notes
|
||||
: - libraries - source only, but can link to C *.so and *.a
|
||||
: - Fork/Exec are coupled together (for coroutine and GC reasons)
|
||||
: - Threading, and multiproc, concurrent logic
|
||||
: -- nice and easy to use
|
||||
: -- Make for tricky handling of C calls (i.e. setns)
|
||||
: - `go get` is handy
|
||||
: - cross-compile without hardly any bootstrapping
|
||||
: -- native compiler supported arches
|
||||
: -- gccgo works for the arch gcc is compiled for
|
||||
: - primitives can seem a bit magical
|
||||
: -- conditional returns
|
||||
: -- for ... range
|
||||
: -- iota
|
||||
: - no ifdefs, but build tags
|
||||
: - error handling, rather than exception catching
|
||||
|
||||
|
||||
*
|
||||
|
||||
.image ./gopher.png
|
||||
|
||||
|
||||
* Overview
|
||||
|
||||
- strongly typed
|
||||
- compiled
|
||||
- stylistically nice
|
||||
- opinionated/idiomatic
|
||||
|
||||
|
||||
*
|
||||
|
||||
.image ./rainbow.jpg
|
||||
|
||||
|
||||
* fully qualified imports
|
||||
|
||||
.code ./imports.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* fast compiles
|
||||
|
||||
(Perhaps other compilers are slow)
|
||||
|
||||
.play ./hello.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* defer
|
||||
|
||||
.code -numbers ./good0.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* Garbage Collected
|
||||
|
||||
- Super convenient
|
||||
- references
|
||||
- completed goroutines
|
||||
|
||||
|
||||
* Garbage Collected
|
||||
|
||||
.link https://twitter.com/brianhatfield/status/634166123605331968 Brian Hatfield GC improvements
|
||||
|
||||
- go1.4 (300ms) -> go1.5 (~30ms)
|
||||
- go1.6.0 (25ms) -> go1.6.3 (5ms)
|
||||
- go1.7.3 (3ms) -> go1.8beta1 (sub ms on 18Gb heap)
|
||||
|
||||
|
||||
* simple exports
|
||||
|
||||
.code ./good1.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* concurrency
|
||||
|
||||
.play -numbers ./pingpong.go /STARTMAIN1/,/STOPMAIN1/
|
||||
.link http://talks.golang.org/2013/advconc.slide Sameer Ajmani - Advanced Concurrency
|
||||
|
||||
|
||||
* cross compiles
|
||||
|
||||
: this could be demo'ed by scp'ing the binaries to fats.userys (aarch64) and piaba.usersys (arm v7)
|
||||
|
||||
(staying away from CGO)
|
||||
|
||||
.play ./hello.go /START1/,/STOP1/
|
||||
|
||||
$> go build ./main.go
|
||||
$> file main
|
||||
main: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
|
||||
$> GOOS=windows GOARCH=386 go build ./main.go
|
||||
$> file main.exe
|
||||
main.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows
|
||||
$> GOOS=openbsd GOARCH=arm go build ./main.go
|
||||
$> file main
|
||||
main: ELF 32-bit LSB executable, ARM, version 1 (OpenBSD), statically linked, for OpenBSD, not stripped
|
||||
$> GOARCH=arm64 go build ./main.go
|
||||
$> file main
|
||||
main: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped
|
||||
|
||||
|
||||
* helpers
|
||||
|
||||
- `go get golang.org/x/tools/cmd/godoc`
|
||||
- `go get github.com/golang/lint/golint`
|
||||
- https://github.com/fatih/vim-go
|
||||
|
||||
- `go vet ./...`
|
||||
- `go test ./...`
|
||||
- `golint -set_exit_status ./...`
|
||||
|
||||
|
||||
*
|
||||
.image ./kanye_imma_bookmarklet.png 250 _
|
||||
.caption _kanye_ by Kayne
|
||||
|
||||
- easy learning curve
|
||||
- `go get`
|
||||
- formatting wars are "over"
|
||||
- shared libraries
|
||||
|
||||
|
||||
*
|
||||
|
||||
: they come along, and affect how you do your work
|
||||
.image ./cats20.gif
|
||||
.caption _halping_hooman_ by cat
|
||||
|
||||
|
||||
* Packaging
|
||||
|
||||
Addresses different concern than distributions
|
||||
|
||||
|
||||
* lack of generics?
|
||||
|
||||
: i don't feel strongly about this, though many do
|
||||
- interfaces - are enough for most
|
||||
- go1.4 introduced go:generate
|
||||
: produce code for Set, Graph etc, for the types needed, but at compile time. No need to reflect.
|
||||
|
||||
|
||||
* Debugging
|
||||
|
||||
- gdb is there, sort of
|
||||
- some known debugging tools for ELF are not useful
|
||||
- fmt.Printf("%#v\n", ...)
|
||||
: show break on main.main and fmt.Println
|
||||
: continue, list, then step, then list, and then face melt
|
||||
|
||||
|
||||
* Concurrency and CGO
|
||||
|
||||
Calls like setns(2) are rough
|
||||
|
||||
(yes, even with runtime.LockOSThread())
|
||||
|
||||
Embedding other languages (like ruby and python that have their green threading)
|
||||
|
||||
|
||||
* Fork/Exec
|
||||
|
||||
Not Separate, but together
|
||||
|
||||
|
||||
*
|
||||
.image ./revenge-of-the-nerds-o.gif
|
||||
.caption _dancin'_ in ROTN
|
||||
|
||||
|
||||
* build tags
|
||||
|
||||
no #ifdef
|
||||
|
||||
.code ./tags.go /START1/,/STOP1/
|
||||
|
||||
or files with *_linux.go like suffix.
|
||||
|
||||
More like extern.
|
||||
|
||||
|
||||
* _
|
||||
|
||||
bit bucket
|
||||
|
||||
|
||||
* channels
|
||||
|
||||
.play ./ugly0.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* iota
|
||||
|
||||
.code ./ugly1.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* for range
|
||||
|
||||
array (or string)
|
||||
|
||||
.play ./primitive1.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* for range
|
||||
|
||||
map
|
||||
|
||||
.play ./primitive2.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* for range
|
||||
|
||||
channel (like an iterator)
|
||||
|
||||
.play ./primitive3.go /START1/,/STOP1/
|
||||
|
||||
|
||||
* for range
|
||||
|
||||
channel
|
||||
|
||||
.code ./primitive3.go /START2/,/STOP2/
|
||||
|
||||
|
||||
* Conclusions?
|
||||
|
||||
|
||||
* use-case
|
||||
|
||||
- like all languages, align with you use-case
|
||||
- get familiar enough to like and dislike it
|
||||
- don't be afraid to try it out
|
||||
|
||||
|
||||
* References
|
||||
|
||||
.link https://golang.org/doc/ Go Documentation
|
||||
.link https://golang.org/doc/effective_go.html Effective Go
|
16
2016/12-intro-to-golang/ugly0.go
Normal file
16
2016/12-intro-to-golang/ugly0.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
// START1 OMIT
|
||||
c := make(chan int)
|
||||
go func() {
|
||||
for i := 0; i < 10; i++ {
|
||||
c <- i
|
||||
}
|
||||
close(c)
|
||||
}()
|
||||
println(<-c)
|
||||
// STOP1 OMIT
|
||||
}
|
22
2016/12-intro-to-golang/ugly1.go
Normal file
22
2016/12-intro-to-golang/ugly1.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// START1 OMIT
|
||||
const (
|
||||
DeviceCreate TaskType = iota
|
||||
DeviceReload
|
||||
DeviceRemove
|
||||
DeviceRemoveAll
|
||||
DeviceSuspend
|
||||
DeviceResume
|
||||
DeviceInfo
|
||||
DeviceDeps
|
||||
)
|
||||
|
||||
// STOP1 OMIT
|
||||
|
||||
type TaskType int
|
||||
|
||||
func main() {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue