Skip to content

Commit

Permalink
Replace go-bindata with vfsgen
Browse files Browse the repository at this point in the history
The go-bindata fork was having some issues with go mod tidy.
  • Loading branch information
wfscheper committed Sep 18, 2019
1 parent d97b2a5 commit 50b013e
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 1,390 deletions.
17 changes: 3 additions & 14 deletions dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate go-bindata -prefix internal/langs/ -o internal/langs/languages.go -pkg langs internal/langs/languages/...

package xkcdpwd

import (
Expand All @@ -26,8 +24,6 @@ import (
"sort"
"strings"

"golang.org/x/text/language"

"github.com/wfscheper/xkcdpwd/internal/langs"
)

Expand Down Expand Up @@ -212,18 +208,11 @@ func (d *Dictionary) Passphrase(n int) ([]string, error) {
return words, nil
}

var matcher = language.NewMatcher([]language.Tag{
language.English,
})

// GetDict returns the dictionary associated with the language code lang.
func GetDict(lang string) *Dictionary {
tag, _ := language.MatchStrings(matcher, lang)
switch tag {
case language.English:
data := langs.MustAsset("languages/en")
return NewDictionary(bytes.NewBuffer(data))
default:
data, err := langs.GetLanguage(lang)
if err != nil {
return nil
}
return NewDictionary(bytes.NewBuffer(data))
}
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module github.com/wfscheper/xkcdpwd

go 1.13

require (
github.com/golangci/golangci-lint v1.18.0 // indirect
github.com/magefile/mage v1.4.0
github.com/golangci/golangci-lint v1.18.0
github.com/magefile/mage v1.9.0
github.com/mattn/goveralls v0.0.2
github.com/pelletier/go-toml v1.2.0
github.com/shuLhan/go-bindata v3.4.0+incompatible
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7
golang.org/x/text v0.3.0
github.com/pborman/uuid v1.2.0 // indirect
github.com/pelletier/go-toml v1.4.0
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect
golang.org/x/text v0.3.2
)

go 1.13
51 changes: 38 additions & 13 deletions go.sum

Large diffs are not rendered by default.

1,380 changes: 29 additions & 1,351 deletions internal/langs/languages.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions internal/langs/languages_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build dev

package langs

import "net/http"

var Languages http.FileSystem = http.Dir("languages")
22 changes: 22 additions & 0 deletions internal/langs/languages_generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build ignore

package main

import (
"log"

"github.com/shurcooL/vfsgen"
"github.com/wfscheper/xkcdpwd/internal/langs"
)

func main() {
err := vfsgen.Generate(langs.Languages, vfsgen.Options{
PackageName: "langs",
BuildTags: "!dev",
VariableName: "Languages",
})
if err != nil {
log.Fatalln(err)
}

}
186 changes: 186 additions & 0 deletions internal/langs/languages_vfsdata.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ func Fmt(ctx context.Context) error {

// Generate generates dictionary files
func Generate(ctx context.Context) error {
rebuild, err := target.Dir(filepath.Join(".", "internal", "langs", "languages.go"), filepath.Join(".", "internal", "langs", "languages"))
dst := filepath.Join(".", "internal", "langs", "languages_vfsdata.go")
src := filepath.Join(".", "internal", "langs", "languages")
rebuild, err := target.Dir(dst, src)
if err != nil {
return err
}
if rebuild {
mg.CtxDeps(ctx, getGobindata)
fmt.Println("running go generate…")
return sh.RunWith(toolsEnv(), goexe, "generate", filepath.Join(".", "dictionary.go"))
return sh.RunWith(toolsEnv(), goexe, "generate", "-x", "./...")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ package xkcdpwd

import (
// tools
_ "github.com/golangci/golangci-lint"
_ "github.com/shuLhan/go-bindata"
_ "github.com/golangci/golangci-lint/pkg/lint"
_ "github.com/mattn/goveralls"
)

0 comments on commit 50b013e

Please sign in to comment.