5. WHAT TO REFACTORWHAT TO REFACTOR
Statically checking Go source for errors and warning
Add benchmark test to improve performance
Add feature to split notebook to individual les
3 . 1
12. GOFMTGOFMT
go fmt < gofmt < goimports
package main
import (
"fmt"
)
func main() {
s := []string{}
var m map[string]interface{}
s = append(s, "a")
s = append(s, "b")
for i, _ := range s {
fmt.Println(i)
m[s[i]] = i
}
}
4 . 7
13. A (maybe) better version
package main
import (
"fmt"
)
func main() {
var s []string
m := map[string]interface{}{}
s = append(s, "a")
s = append(s, "b")
for i := range s {
fmt.Println(i)
m[s[i]] = i
}
}
4 . 8
28. OTHER POSSIBLE REFACTORINGOTHER POSSIBLE REFACTORING
Use interface more often, especially io.Reader and
io.Writer
Add more test to increase test coverage
5 . 7
29. Go Releaser
before:
hooks:
builds:
- env:
- CGO_ENABLED=0
- goos:
- darwin
- linux
- windows
- ignore:
- goos: darwin
goarch: 386
archive:
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{
replacements:
darwin: Darwin
5 . 8