First impressions of Go
-
Upload
yusaku-ogawa -
Category
Software
-
view
783 -
download
3
Transcript of First impressions of Go
First impressions of GoOGAWA Yusaku
About me
● OGAWA Yusaku
● HDE, Inc.
● Newbie gopher
So good
● Go commands○ go build○ go run○ go fmt○ go test○ go get○ etc.
So good: go fmt
$ go fmt main.go<Before> <After>
package mainimport "fmt"func main(){ sum:=0 for i:=0;i<10;i++{sum+=i} fmt.Println(sum)}
package main
import "fmt"
func main() {sum := 0for i := 0; i < 10; i++ {
sum += i}fmt.Println(sum)
}
So good: go test$ lsfoo.go foo_test.go
$ go testPASSok _/path/to/src/foo 0.027s
Good habit
Not so good (for me)
● Library○ The standard library
(In genaral, good enough for writing code, but...)
○ Third-party libraries
Not so good: The standard library
● net/mail (Mail parsing library)http://golang.org/pkg/net/mail/
eml, _ := os.Open("hello.eml")msg, _ := mail.ReadMessage(eml)msg.Header.Get("Subject")
<Mail>Received: from example.net ([x.x.x.x]) by example.org (foo); Fri, 30 May 2014 00:00:00 +0900 (JST)Received: from example.com ([y.y.y.y]) by example.net (bar); Fri, 30 May 2014 00:00:00 +0900 (JST)Date: Fri, 30 May 2014 00:00:00 +0900From: from <[email protected]>Subject: This is a subject header
Hello
<Output>msg.Header.Get("Subject")=> This is a subject header
msg.Header.Get("Received")=> Received: from example.net ([x.x.x.x]) by example.org (foo); Fri, 30 May 2014 00:00:00 +0900 (JST)
http://golang.org/src/pkg/net/mail/message.go#L103 103 104 // A Header represents the key-value pairs in a mail message header. 105 type Header map[string][]string 106
<UTF-8>=?UTF-8?B?SGVsbG8sIEdvbGFuZy4=?==> Hello, Golang.
<ISO-2022-JP>=?ISO-2022-JP?B?GyRCJE8kbSE8GyhCLCBHb2xhbmcu?==> Error: missing word in phrase
http://golang.org/src/pkg/net/mail/message.go#L445 445 charset, enc := strings.ToLower(fields[1]), strings.ToLower(fields[2]) 446 if charset != "iso-8859-1" && charset != "utf-8" { 447 return "", fmt.Errorf("mail: charset not supported: %q", charset) 448 }
Not so good: Thirt-party librariesThere are too many standards
● e.g. Iconv bindings for Go○ github.com/qiniu/iconv○ github.com/djimenez/iconv-go○ github.com/xushiwei/go-iconv○ github.com/hwch/iconv○ github.com/xuyu/iconv○ github.com/erkl/iconv○ github.com/moovweb/goconv○ github.com/ChaimHong/go-iconv○ github.com/zhigangc/goconv○ github.com/vedranvuk/bindiconv○ github.com/jhiter/goiconv
http://www.xkcd.com/927/
Thank you