diff options
author | Nick White <git@njw.name> | 2021-06-22 14:04:24 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2021-06-22 14:04:24 +0100 |
commit | 8e5ad7b2ccb59d29adf520e17767f77eea23e6c2 (patch) | |
tree | 3a8e519a832a4b3b1b1a55f5ab9c0866bee9ce94 /cmd/rescribe | |
parent | 74e75ed54d4075c1ffeeba22513a3a2edd25fee5 (diff) |
rescribe: Add go generate command to download the needed files to embed
Diffstat (limited to 'cmd/rescribe')
-rw-r--r-- | cmd/rescribe/getembeds.go | 55 | ||||
-rw-r--r-- | cmd/rescribe/main.go | 2 |
2 files changed, 57 insertions, 0 deletions
diff --git a/cmd/rescribe/getembeds.go b/cmd/rescribe/getembeds.go new file mode 100644 index 0000000..b2b5392 --- /dev/null +++ b/cmd/rescribe/getembeds.go @@ -0,0 +1,55 @@ +// Copyright 2021 Nick White. +// Use of this source code is governed by the GPLv3 +// license that can be found in the LICENSE file. + +// +build ignore + +// this downloads the needed files to embed into the binary, +// and is run by `go generate` +package main + +import ( + "fmt" + "io" + "os" + "path" + "net/http" +) + +func dl(url string) error { + fn := path.Base(url) + + f, err := os.Create(fn) + if err != nil { + return fmt.Errorf("Error creating file %s: %v", fn, err) + } + defer f.Close() + + r, err := http.Get(url) + if err != nil { + return fmt.Errorf("Error getting url %s: %v", url, err) + } + defer r.Body.Close() + + _, err = io.Copy(f, r.Body) + if err != nil { + return fmt.Errorf("Error saving %s: %v", fn, err) + } + + return nil +} + +func main() { + urls := []string { + "https://rescribe.xyz/rescribe/embeds/tessdata.20210622.zip", + "https://rescribe.xyz/rescribe/embeds/tesseract-w32-v5.0.0-alpha.20210506.zip", + } + for _, v := range urls { + fmt.Printf("Downloading %s\n", v) + err := dl(v) + if err != nil { + fmt.Printf("Error downloading %s: %v\n", v, err) + os.Exit(1) + } + } +} diff --git a/cmd/rescribe/main.go b/cmd/rescribe/main.go index 3325282..c000190 100644 --- a/cmd/rescribe/main.go +++ b/cmd/rescribe/main.go @@ -7,6 +7,8 @@ // a single book by the pipeline into one command. package main +//go:generate go run getembeds.go + import ( "archive/zip" "bytes" |