diff --git a/Gopkg.lock b/Gopkg.lock index deaf2c3..fb5097f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,66 +2,93 @@ [[projects]] + digest = "1:bcb38c8fc9b21bb8682ce2d605a7d4aeb618abc7f827e3ac0b27c0371fdb23fb" name = "github.com/golang/protobuf" packages = ["proto"] + pruneopts = "" revision = "925541529c1fa6821df4e44ce2723319eb2be768" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:deffa1949bb382121a8d38a7540feeb80122a9e74103e0195fff6a1ca4088ecb" name = "github.com/google/go-github" packages = ["github"] + pruneopts = "" revision = "b1658317c4f5c8dd7000d94ab8a9b56039412cc6" [[projects]] branch = "master" + digest = "1:9abc49f39e3e23e262594bb4fb70abf74c0c99e94f99153f43b143805e850719" name = "github.com/google/go-querystring" packages = ["query"] + pruneopts = "" revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a" [[projects]] + digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" name = "github.com/inconshreveable/mousetrap" packages = ["."] + pruneopts = "" revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" version = "v1.0" +[[projects]] + digest = "1:79c3c0b8805e9331a87c459b37dd007d4389cc511dfa2beeae1d6f35986cd4a4" + name = "github.com/rakyll/statik" + packages = ["fs"] + pruneopts = "" + revision = "3bac566d30cdbeddef402a80f3d6305860e59f12" + version = "v0.1.6" + [[projects]] branch = "master" + digest = "1:50b5be512f924d289f20e8b2aef8951d98b9bd8c44666cf169514906df597a4c" name = "github.com/skratchdot/open-golang" packages = ["open"] + pruneopts = "" revision = "75fb7ed4208cf72d323d7d02fd1a5964a7a9073c" [[projects]] branch = "master" + digest = "1:3432164f2ad1188a576d877969c092967a777c79f0020e0dd95b62cb89fb8f35" name = "github.com/spf13/cobra" packages = ["."] + pruneopts = "" revision = "a1e4933ab784095895e33dbe9f001ba10cfe2060" [[projects]] + digest = "1:261bc565833ef4f02121450d74eb88d5ae4bd74bfe5d0e862cddb8550ec35000" name = "github.com/spf13/pflag" packages = ["."] + pruneopts = "" revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:b4ba046df563f56fe42b6270b20039107a37e1ab47c97aa47a16f848aa5b6d9a" name = "golang.org/x/net" packages = [ "context", - "context/ctxhttp" + "context/ctxhttp", ] + pruneopts = "" revision = "cbe0f9307d0156177f9dd5dc85da1a31abc5f2fb" [[projects]] branch = "master" + digest = "1:dd57134ebff8e1a1a77c9f145a28cad8470da6bb9053d6ff2bc552ecd7f8bc92" name = "golang.org/x/oauth2" packages = [ ".", - "internal" + "internal", ] + pruneopts = "" revision = "543e37812f10c46c622c9575afd7ad22f22a12ba" [[projects]] + digest = "1:934fb8966f303ede63aa405e2c8d7f0a427a05ea8df335dfdc1833dd4d40756f" name = "google.golang.org/appengine" packages = [ "internal", @@ -70,20 +97,30 @@ "internal/log", "internal/remote_api", "internal/urlfetch", - "urlfetch" + "urlfetch", ] + pruneopts = "" revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" version = "v1.0.0" [[projects]] + branch = "v2" + digest = "1:60ccede33d50c82c86e907255319a6f40dca4ac395e5ee143638176d3b871069" name = "gopkg.in/yaml.v2" packages = ["."] - revision = "7f97868eec74b32b0982dd158a51a446d1da7eb5" - version = "v2.1.1" + pruneopts = "" + revision = "7b8349ac747c6a24702b762d2c4fd9266cf4f1d6" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "7a30dc8fe8d797904172f7d7003a8d1e80f1b9f8b8e4d5c84ca8ce661f13f22b" + input-imports = [ + "github.com/google/go-github/github", + "github.com/rakyll/statik/fs", + "github.com/skratchdot/open-golang/open", + "github.com/spf13/cobra", + "golang.org/x/oauth2", + "gopkg.in/yaml.v2", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 41239ac..7756e6c 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -40,3 +40,7 @@ [[constraint]] branch = "v2" name = "gopkg.in/yaml.v2" + +[[constraint]] + name = "github.com/rakyll/statik" + version = "0.1.6" diff --git a/Makefile b/Makefile index a0cde4c..f37d14c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME := github-nippou -SRCS := $(shell find . -type f ! -path ./lib/bindata.go -name '*.go' ! -name '*_test.go') +SRCS := $(shell find . -type f ! -path ./statik/statik.go -name '*.go' ! -name '*_test.go') CONFIGS := $(wildcard config/*) VERSION := v$(shell grep 'const Version ' lib/version.go | sed -E 's/.*"(.+)"$$/\1/') PACKAGES := $(shell go list ./...) @@ -12,7 +12,7 @@ all: $(NAME) # Install dependencies for development .PHONY: deps -deps: dep go-bindata +deps: dep statik dep ensure .PHONY: dep @@ -21,17 +21,17 @@ ifeq ($(shell command -v dep 2> /dev/null),) go get github.com/golang/dep/cmd/dep endif -.PHONY: go-bindata -go-bindata: -ifeq ($(shell command -v go-bindata 2> /dev/null),) - go get github.com/jteeuwen/go-bindata/... +.PHONY: statik +statik: +ifeq ($(shell command -v statik 2> /dev/null),) + go get github.com/rakyll/statik endif # Build binary -$(NAME): lib/bindata.go $(SRCS) +$(NAME): statik/statik.go $(SRCS) go build -o $(NAME) -lib/bindata.go: $(CONFIGS) +statik/statik.go: $(CONFIGS) go generate # Install binary to $GOPATH/bin @@ -46,7 +46,7 @@ clean: # Test for development .PHONY: test -test: lib/bindata.go +test: statik/statik.go go test -v $(PACKAGES) # Test for CI @@ -54,7 +54,7 @@ test: lib/bindata.go test-all: deps-test-all vet lint test .PHONY: deps-test-all -deps-test-all: dep go-bindata golint lib/bindata.go +deps-test-all: dep statik golint statik/statik.go dep ensure .PHONY: golint @@ -103,7 +103,7 @@ cross-build: deps-cross-build gox -os="darwin linux windows" -arch="386 amd64" -output "pkg/{{.OS}}_{{.Arch}}/{{.Dir}}" .PHONY: deps-cross-build -deps-cross-build: deps lib/bindata.go gox +deps-cross-build: deps statik/statik.go gox .PHONY: gox gox: diff --git a/lib/bindata.go b/lib/bindata.go deleted file mode 100644 index 59bd32d..0000000 --- a/lib/bindata.go +++ /dev/null @@ -1,217 +0,0 @@ -// Code generated by go-bindata. -// sources: -// config/settings.yml -// DO NOT EDIT! - -package lib - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" -) -type asset struct { - bytes []byte - info os.FileInfo -} - -type bindataFileInfo struct { - name string - size int64 - mode os.FileMode - modTime time.Time -} - -func (fi bindataFileInfo) Name() string { - return fi.name -} -func (fi bindataFileInfo) Size() int64 { - return fi.size -} -func (fi bindataFileInfo) Mode() os.FileMode { - return fi.mode -} -func (fi bindataFileInfo) ModTime() time.Time { - return fi.modTime -} -func (fi bindataFileInfo) IsDir() bool { - return false -} -func (fi bindataFileInfo) Sys() interface{} { - return nil -} - -var _configSettingsYml = []byte(`format: - subject: '### %{subject}' - line: '* [%{title}](%{url}) by @[%{user}](https://github.com/%{user}) %{status}' -dictionary: - status: - merged: '**merged!**' - closed: '**closed!**' -`) - -func configSettingsYmlBytes() ([]byte, error) { - return _configSettingsYml, nil -} - -func configSettingsYml() (*asset, error) { - bytes, err := configSettingsYmlBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "config/settings.yml", size: 193, mode: os.FileMode(420), modTime: time.Unix(1507882516, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) - } - return a.bytes, nil - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// MustAsset is like Asset but panics when Asset would return an error. -// It simplifies safe initialization of global variables. -func MustAsset(name string) []byte { - a, err := Asset(name) - if err != nil { - panic("asset: Asset(" + name + "): " + err.Error()) - } - - return a -} - -// AssetInfo loads and returns the asset info for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) - } - return a.info, nil - } - return nil, fmt.Errorf("AssetInfo %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() (*asset, error){ - "config/settings.yml": configSettingsYml, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for childName := range node.Children { - rv = append(rv, childName) - } - return rv, nil -} - -type bintree struct { - Func func() (*asset, error) - Children map[string]*bintree -} -var _bintree = &bintree{nil, map[string]*bintree{ - "config": &bintree{nil, map[string]*bintree{ - "settings.yml": &bintree{configSettingsYml, map[string]*bintree{}}, - }}, -}} - -// RestoreAsset restores an asset under the given directory -func RestoreAsset(dir, name string) error { - data, err := Asset(name) - if err != nil { - return err - } - info, err := AssetInfo(name) - if err != nil { - return err - } - err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) - if err != nil { - return err - } - err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) - if err != nil { - return err - } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil -} - -// RestoreAssets restores an asset under the given directory recursively -func RestoreAssets(dir, name string) error { - children, err := AssetDir(name) - // File - if err != nil { - return RestoreAsset(dir, name) - } - // Dir - for _, child := range children { - err = RestoreAssets(dir, filepath.Join(name, child)) - if err != nil { - return err - } - } - return nil -} - -func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) -} - diff --git a/lib/settings.go b/lib/settings.go index ee7e3ff..43e803d 100644 --- a/lib/settings.go +++ b/lib/settings.go @@ -4,12 +4,17 @@ import ( "context" "errors" "fmt" + "io/ioutil" "os" "os/exec" "strconv" "strings" + // Import ./config/* + _ "github.com/masutaka/github-nippou/statik" + "github.com/google/go-github/github" + "github.com/rakyll/statik/fs" "golang.org/x/oauth2" "gopkg.in/yaml.v2" ) @@ -165,6 +170,22 @@ func getDefaultSettingsURL() string { } func getDefaultSettingsYml() (string, error) { - yml, err := Asset("config/settings.yml") - return string(yml), err + statikFS, err := fs.New() + if err != nil { + return "", err + } + + file, err := statikFS.Open("/settings.yml") + if err != nil { + return "", err + } + + defer file.Close() + + yml, err := ioutil.ReadAll(file) + if err != nil { + return "", err + } + + return string(yml), nil } diff --git a/main.go b/main.go index 8334911..6b7786e 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -//go:generate go-bindata -nocompress -pkg lib -o lib/bindata.go config +//go:generate statik -src=./config -m import ( "fmt" diff --git a/statik/statik.go b/statik/statik.go new file mode 100644 index 0000000..8a92252 --- /dev/null +++ b/statik/statik.go @@ -0,0 +1,13 @@ +// Code generated by statik. DO NOT EDIT. + +// Package statik contains static assets. +package statik + +import ( + "github.com/rakyll/statik/fs" +) + +func init() { + data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\x00\x00!(\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00 \x00settings.ymlUT\x05\x00\x01\x80Cm8,\x8d1\xae\x84 \x14E{Wq\x7f\x0cA)\xbe=\xd5\xec\xc3X(2\xca\x04e\x02\x8f\xc2\x10\xf6>\x11\xe9\xce{'\xb9\xe7\xed\xfc1\x93l\x80\x10\x97\x8fV$\xc1\xdb\xb6\x05K\xf5\xce\xbc\x01\xac9\xb5\x04\x17\x18Y\"CV\xe7\xa9c)z\x9b{,\x17^#K1h\x9f\xa7n'\xfa\x069\x0c\x9b\xa1=.\xff\xca\x1dCu\xfd\xbdI3\xc5\x90y\xb3\x1aE\xc6\x9d\xb3\xbfJ\xba\xbco\x02\x0e\xed7\xbd\xde1\xf1\xe0\x9f\x10\xbc\x18e]\xa8\xe6\xc1b~\x01\x00\x00\xff\xffPK\x07\x08\xc4r\x85G\x8f\x00\x00\x00\xc1\x00\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x00\x00!(\xc4r\x85G\x8f\x00\x00\x00\xc1\x00\x00\x00\x0c\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00settings.ymlUT\x05\x00\x01\x80Cm8PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00C\x00\x00\x00\xd2\x00\x00\x00\x00\x00" + fs.Register(data) +}