Add go fmt to check format of code

This commit is contained in:
Iwasaki Yudai 2015-08-20 16:45:06 +09:00
parent 161d29b0b9
commit 6a43836f0b
2 changed files with 57 additions and 56 deletions

View File

@ -12,11 +12,11 @@ import (
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"strings"
"os"
"time"
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"strings"
"time"
) )
func bindataRead(data []byte, name string) ([]byte, error) { func bindataRead(data []byte, name string) ([]byte, error) {
@ -45,9 +45,9 @@ type asset struct {
} }
type bindataFileInfo struct { type bindataFileInfo struct {
name string name string
size int64 size int64
mode os.FileMode mode os.FileMode
modTime time.Time modTime time.Time
} }
@ -86,7 +86,7 @@ func bindataGottyJs() (*asset, error) {
} }
info := bindataFileInfo{name: "bindata/gotty.js", size: 1398, mode: os.FileMode(436), modTime: time.Unix(1439873108, 0)} info := bindataFileInfo{name: "bindata/gotty.js", size: 1398, mode: os.FileMode(436), modTime: time.Unix(1439873108, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -106,7 +106,7 @@ func bindataHtermJs() (*asset, error) {
} }
info := bindataFileInfo{name: "bindata/hterm.js", size: 522491, mode: os.FileMode(292), modTime: time.Unix(1439767987, 0)} info := bindataFileInfo{name: "bindata/hterm.js", size: 522491, mode: os.FileMode(292), modTime: time.Unix(1439767987, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -126,7 +126,7 @@ func bindataIndexHtml() (*asset, error) {
} }
info := bindataFileInfo{name: "bindata/index.html", size: 254, mode: os.FileMode(436), modTime: time.Unix(1439872871, 0)} info := bindataFileInfo{name: "bindata/index.html", size: 254, mode: os.FileMode(436), modTime: time.Unix(1439872871, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -149,7 +149,7 @@ func Asset(name string) ([]byte, error) {
// It simplifies safe initialization of global variables. // It simplifies safe initialization of global variables.
func MustAsset(name string) []byte { func MustAsset(name string) []byte {
a, err := Asset(name) a, err := Asset(name)
if (err != nil) { if err != nil {
panic("asset: Asset(" + name + "): " + err.Error()) panic("asset: Asset(" + name + "): " + err.Error())
} }
@ -182,8 +182,8 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() (*asset, error){
"bindata/gotty.js": bindataGottyJs, "bindata/gotty.js": bindataGottyJs,
"bindata/hterm.js": bindataHtermJs, "bindata/hterm.js": bindataHtermJs,
"bindata/index.html": bindataIndexHtml, "bindata/index.html": bindataIndexHtml,
} }
@ -223,64 +223,61 @@ func AssetDir(name string) ([]string, error) {
} }
type bintree struct { type bintree struct {
Func func() (*asset, error) Func func() (*asset, error)
Children map[string]*bintree Children map[string]*bintree
} }
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"bindata": &bintree{nil, map[string]*bintree{ "bindata": &bintree{nil, map[string]*bintree{
"gotty.js": &bintree{bindataGottyJs, map[string]*bintree{ "gotty.js": &bintree{bindataGottyJs, map[string]*bintree{}},
}}, "hterm.js": &bintree{bindataHtermJs, map[string]*bintree{}},
"hterm.js": &bintree{bindataHtermJs, map[string]*bintree{ "index.html": &bintree{bindataIndexHtml, map[string]*bintree{}},
}},
"index.html": &bintree{bindataIndexHtml, map[string]*bintree{
}},
}}, }},
}} }}
// RestoreAsset restores an asset under the given directory // RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error { func RestoreAsset(dir, name string) error {
data, err := Asset(name) data, err := Asset(name)
if err != nil { if err != nil {
return err return err
} }
info, err := AssetInfo(name) info, err := AssetInfo(name)
if err != nil { if err != nil {
return err return err
} }
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil { if err != nil {
return err return err
} }
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil { if err != nil {
return err return err
} }
return nil return nil
} }
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
// File // File
if err != nil { if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} }
// Dir // Dir
for _, child := range children { for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child)) err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil { if err != nil {
return err return err
} }
} }
return nil return nil
} }
func _filePath(dir, name string) string { func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
} }

View File

@ -8,6 +8,10 @@ build:
code: | code: |
go get github.com/tools/godep go get github.com/tools/godep
godep restore godep restore
- script:
name: check format
code: |
if [ `go fmt ./... | wc -l` -gt 0 ]; then echo "go fmt error"; exit 1; fi
- tcnksm/gox: - tcnksm/gox:
os: "darwin linux" os: "darwin linux"
arch: "amd64" arch: "amd64"