mirror of
https://github.com/vbatts/talks.git
synced 2025-06-02 01:52:30 +00:00
2016-12: brush up this talk for an intro
This commit is contained in:
parent
1b8e5c7a36
commit
68f582d393
18 changed files with 513 additions and 0 deletions
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 {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue