Speakers on November 6, 2017
The thunder talks are the second round of lightning talks from many speakers.
Note: This post was live-blogged at dotGo 2017. Let us know on Twitter (@sourcegraph) if we missed anything. All content is from the talk; any mistakes or misrepresentations are our fault, not the speaker's.
Ron Evans
Laurent Leveque
From Go to Android - gomobile bind
byte[]
go build buildmode=c-shared
Will have to write C code to manage memory. This is tricky and repetitive, so you can just write it once and use go to generate the glue code.
go/parser
and go/ast
to naviage your Go code programmaticallytext/template
//go:generate
to trigger your code generatorYou can easily combine this by serializing your inputs and outputs with Protobuf
Protobuf:
protoc --go_out=plugins=myStubGenerator:$(pwd) *.proto
protoc-gen-go
is written in Go and has a plugin system.Conclusion:
Diana Ortega
Mickael Remond
Cloud-native way:
Benefits
Marcel van Lohuizen
func writeToGS(ctx context.Context, bucket, dst, src string) (err error) {
client, err := storage.NewClient(ctx)
if err != nil {
return err
}
defer client.Close()
w := client.Bucket(bucket).Object(dst).NewWriter(ctx)
defer w.CloseWithError(err)
_, err = io.Copy(w, r)
return err
}
The above code handles some errors, but is not fully correct:
Putting it all together the code becomes very complicated:
func writeToGS(ctx context.Context, bucket, dst string, r io.Reader) (err error) {
client, err := storage.NewClient(ctx)
if err != nil {
return err
}
defer client.Close()
w := client.Bucket(bucket).Object(dst).NewWriter(ctx)
err = errPanicking
defer func() {
if err != nil {
_ = w.CloseWithError(err)
} else {
err = w.Close()
}
}
_, err = io.Copy(w, r) {
return err
}
How to simplify? Semantics first. An error is recoverable, a panic is not (sort of). Marcel created a burner package github.com/mpvl/errc which unifies error panic and defer. It funnel all errors, including panics, to a single error variable:
func writeToGS(ctx context.Context, bucket, dst, src string) (err error) {
e := errc.Catch(&err)
defer e.Handle()
client, err := storage.NewClient(ctx)
e.Must(err)
e.Defer(client.Close, errc.Discard)
w := client.Bucket(bucket).Object(dst).NewWriter(ctx)
e.Defer(w.CloseWithError)
_, err = io.Copy(w, r)
e.Must(err)
}