aboutsummaryrefslogtreecommitdiff
path: root/cmd/within.website
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-06-15 20:07:29 -0400
committerChristine Dodrill <me@christine.website>2019-06-15 20:09:17 -0400
commit598268d233e69586bcc5886fff149b506dc496e5 (patch)
treefbd0071cd82e08dab34103823ed2134a6473768f /cmd/within.website
parentd6c93f6c9ebe6efa26180d04cfeedda9ddec31c6 (diff)
downloadx-598268d233e69586bcc5886fff149b506dc496e5.tar.xz
x-598268d233e69586bcc5886fff149b506dc496e5.zip
cmd/within.website: use vfsgen
Diffstat (limited to 'cmd/within.website')
-rw-r--r--cmd/within.website/assets_vfsdata.go186
-rw-r--r--cmd/within.website/bindata.go105
-rw-r--r--cmd/within.website/build.go53
-rw-r--r--cmd/within.website/dev.go7
-rw-r--r--cmd/within.website/main.go8
5 files changed, 231 insertions, 128 deletions
diff --git a/cmd/within.website/assets_vfsdata.go b/cmd/within.website/assets_vfsdata.go
new file mode 100644
index 0000000..c678415
--- /dev/null
+++ b/cmd/within.website/assets_vfsdata.go
@@ -0,0 +1,186 @@
+// Code generated by vfsgen; DO NOT EDIT.
+
+// +build !dev
+
+package main
+
+import (
+ "bytes"
+ "compress/gzip"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "os"
+ pathpkg "path"
+ "time"
+)
+
+// assets statically implements the virtual filesystem provided to vfsgen.
+var assets = func() http.FileSystem {
+ fs := vfsgen۰FS{
+ "/": &vfsgen۰DirInfo{
+ name: "/",
+ modTime: time.Date(2019, 6, 8, 23, 23, 58, 831215970, time.UTC),
+ },
+ "/gruvbox.css": &vfsgen۰CompressedFileInfo{
+ name: "gruvbox.css",
+ modTime: time.Date(2019, 6, 8, 23, 23, 58, 831722250, time.UTC),
+ uncompressedSize: 968,
+
+ compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x91\xcf\x6e\xa3\x30\x10\xc6\xef\x7e\x8a\x91\x72\xd9\x95\xa0\x8a\xa1\xa4\xc4\xb9\xec\xab\xf8\xcf\x10\x5b\xc5\x98\x35\x4e\x37\xd5\x8a\x77\x5f\x61\xa0\x01\xb7\x5d\x73\xc0\x1a\xcf\x7c\x33\xf3\xfd\x2c\x37\x1d\xfc\x25\x00\x8d\xeb\x42\xde\x70\x6b\xda\x77\x06\xd6\x75\x6e\xe8\xb9\xc4\xec\x71\xbd\x10\x00\xcb\xef\xf9\x1f\xa3\x82\x66\x50\xd6\x1e\xed\x14\xeb\xb9\x52\xa6\xbb\x32\x28\x96\x80\xe5\xfe\x6a\x3a\x06\xfc\x16\xdc\x85\x8c\x84\x30\x36\x60\x8b\x32\x18\x37\xb7\x12\x5c\xbe\x5e\xbd\xbb\x75\x8a\xc1\x41\x95\xf5\xe9\x2c\x62\x9e\x70\xea\xfd\x73\x42\x51\x4f\xdf\x24\x2c\x5d\xeb\x3c\x83\x78\x0e\x28\x94\x10\x45\xac\xeb\x3d\x26\x65\xf9\x92\x7a\x28\x65\x59\x97\xa7\xdd\x98\x74\x9e\x52\x38\xaf\xd0\x33\x38\x46\x09\x9e\x01\x67\x5c\x06\xf3\x86\xd3\xed\xcd\x0c\x26\xa0\x8a\xaa\xab\x94\xa0\xa7\xa2\x8e\x52\x5f\xf4\xa1\xaa\x38\x16\x34\x4a\x69\x9a\x81\x2e\x32\xd0\x65\x06\xfa\x39\x03\x5d\x45\x99\xd9\x95\x5c\xb8\x10\x9c\x65\xf0\x44\xa3\x5b\xd3\xd6\xad\x93\xaf\xbf\x6f\x2e\x2c\x4b\xc4\xb9\xf2\x16\x9b\xc0\x80\xf6\x77\x18\x5c\x6b\x14\x1c\x84\xe2\x78\x2e\xb7\xfe\x1e\x9f\x2a\xb4\x40\x8f\xfd\x7d\xb7\xdf\x36\x3c\x12\xf2\xcb\xa2\x32\x1c\x7e\xf4\x1e\x1b\xf4\xc3\x3c\x71\x3e\x48\x8d\x16\x19\xb4\xe6\xaa\xc3\xcf\xd8\x78\x6a\xbd\xf8\x3f\x9f\x1d\x85\x46\x34\x54\xbe\x5c\x3e\x1e\x77\x2c\x1e\x2e\x03\x8c\x24\xfe\x56\x26\xa9\xd4\x87\x63\x2b\xbf\x35\x25\xe5\xb3\x14\x3e\x28\x6d\xc4\xff\x43\x6b\x37\xdd\x86\xd9\xb7\x73\x34\xe7\xa6\x52\x2f\x3b\xf9\x6f\x08\xce\xe7\x6b\x8e\x9b\xea\x84\xe7\x76\x8f\xcf\x54\x4f\x55\x25\xab\xe7\x4b\xa2\x9e\xb2\x4d\x1c\x4a\x1f\x47\x32\x92\x7f\x01\x00\x00\xff\xff\xab\xef\x35\x5a\xc8\x03\x00\x00"),
+ },
+ }
+ fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
+ fs["/gruvbox.css"].(os.FileInfo),
+ }
+
+ return fs
+}()
+
+type vfsgen۰FS map[string]interface{}
+
+func (fs vfsgen۰FS) Open(path string) (http.File, error) {
+ path = pathpkg.Clean("/" + path)
+ f, ok := fs[path]
+ if !ok {
+ return nil, &os.PathError{Op: "open", Path: path, Err: os.ErrNotExist}
+ }
+
+ switch f := f.(type) {
+ case *vfsgen۰CompressedFileInfo:
+ gr, err := gzip.NewReader(bytes.NewReader(f.compressedContent))
+ if err != nil {
+ // This should never happen because we generate the gzip bytes such that they are always valid.
+ panic("unexpected error reading own gzip compressed bytes: " + err.Error())
+ }
+ return &vfsgen۰CompressedFile{
+ vfsgen۰CompressedFileInfo: f,
+ gr: gr,
+ }, nil
+ case *vfsgen۰DirInfo:
+ return &vfsgen۰Dir{
+ vfsgen۰DirInfo: f,
+ }, nil
+ default:
+ // This should never happen because we generate only the above types.
+ panic(fmt.Sprintf("unexpected type %T", f))
+ }
+}
+
+// vfsgen۰CompressedFileInfo is a static definition of a gzip compressed file.
+type vfsgen۰CompressedFileInfo struct {
+ name string
+ modTime time.Time
+ compressedContent []byte
+ uncompressedSize int64
+}
+
+func (f *vfsgen۰CompressedFileInfo) Readdir(count int) ([]os.FileInfo, error) {
+ return nil, fmt.Errorf("cannot Readdir from file %s", f.name)
+}
+func (f *vfsgen۰CompressedFileInfo) Stat() (os.FileInfo, error) { return f, nil }
+
+func (f *vfsgen۰CompressedFileInfo) GzipBytes() []byte {
+ return f.compressedContent
+}
+
+func (f *vfsgen۰CompressedFileInfo) Name() string { return f.name }
+func (f *vfsgen۰CompressedFileInfo) Size() int64 { return f.uncompressedSize }
+func (f *vfsgen۰CompressedFileInfo) Mode() os.FileMode { return 0444 }
+func (f *vfsgen۰CompressedFileInfo) ModTime() time.Time { return f.modTime }
+func (f *vfsgen۰CompressedFileInfo) IsDir() bool { return false }
+func (f *vfsgen۰CompressedFileInfo) Sys() interface{} { return nil }
+
+// vfsgen۰CompressedFile is an opened compressedFile instance.
+type vfsgen۰CompressedFile struct {
+ *vfsgen۰CompressedFileInfo
+ gr *gzip.Reader
+ grPos int64 // Actual gr uncompressed position.
+ seekPos int64 // Seek uncompressed position.
+}
+
+func (f *vfsgen۰CompressedFile) Read(p []byte) (n int, err error) {
+ if f.grPos > f.seekPos {
+ // Rewind to beginning.
+ err = f.gr.Reset(bytes.NewReader(f.compressedContent))
+ if err != nil {
+ return 0, err
+ }
+ f.grPos = 0
+ }
+ if f.grPos < f.seekPos {
+ // Fast-forward.
+ _, err = io.CopyN(ioutil.Discard, f.gr, f.seekPos-f.grPos)
+ if err != nil {
+ return 0, err
+ }
+ f.grPos = f.seekPos
+ }
+ n, err = f.gr.Read(p)
+ f.grPos += int64(n)
+ f.seekPos = f.grPos
+ return n, err
+}
+func (f *vfsgen۰CompressedFile) Seek(offset int64, whence int) (int64, error) {
+ switch whence {
+ case io.SeekStart:
+ f.seekPos = 0 + offset
+ case io.SeekCurrent:
+ f.seekPos += offset
+ case io.SeekEnd:
+ f.seekPos = f.uncompressedSize + offset
+ default:
+ panic(fmt.Errorf("invalid whence value: %v", whence))
+ }
+ return f.seekPos, nil
+}
+func (f *vfsgen۰CompressedFile) Close() error {
+ return f.gr.Close()
+}
+
+// vfsgen۰DirInfo is a static definition of a directory.
+type vfsgen۰DirInfo struct {
+ name string
+ modTime time.Time
+ entries []os.FileInfo
+}
+
+func (d *vfsgen۰DirInfo) Read([]byte) (int, error) {
+ return 0, fmt.Errorf("cannot Read from directory %s", d.name)
+}
+func (d *vfsgen۰DirInfo) Close() error { return nil }
+func (d *vfsgen۰DirInfo) Stat() (os.FileInfo, error) { return d, nil }
+
+func (d *vfsgen۰DirInfo) Name() string { return d.name }
+func (d *vfsgen۰DirInfo) Size() int64 { return 0 }
+func (d *vfsgen۰DirInfo) Mode() os.FileMode { return 0755 | os.ModeDir }
+func (d *vfsgen۰DirInfo) ModTime() time.Time { return d.modTime }
+func (d *vfsgen۰DirInfo) IsDir() bool { return true }
+func (d *vfsgen۰DirInfo) Sys() interface{} { return nil }
+
+// vfsgen۰Dir is an opened dir instance.
+type vfsgen۰Dir struct {
+ *vfsgen۰DirInfo
+ pos int // Position within entries for Seek and Readdir.
+}
+
+func (d *vfsgen۰Dir) Seek(offset int64, whence int) (int64, error) {
+ if offset == 0 && whence == io.SeekStart {
+ d.pos = 0
+ return 0, nil
+ }
+ return 0, fmt.Errorf("unsupported Seek in directory %s", d.name)
+}
+
+func (d *vfsgen۰Dir) Readdir(count int) ([]os.FileInfo, error) {
+ if d.pos >= len(d.entries) && count > 0 {
+ return nil, io.EOF
+ }
+ if count <= 0 || count > len(d.entries)-d.pos {
+ count = len(d.entries) - d.pos
+ }
+ e := d.entries[d.pos : d.pos+count]
+ d.pos += count
+ return e, nil
+}
diff --git a/cmd/within.website/bindata.go b/cmd/within.website/bindata.go
deleted file mode 100644
index 86f5512..0000000
--- a/cmd/within.website/bindata.go
+++ /dev/null
@@ -1,105 +0,0 @@
-package main
-
-import (
- "bytes"
- "compress/gzip"
- "fmt"
- "io"
- "strings"
-)
-
-func bindata_read(data []byte, name string) ([]byte, error) {
- gz, err := gzip.NewReader(bytes.NewBuffer(data))
- if err != nil {
- return nil, fmt.Errorf("Read %q: %v", name, err)
- }
-
- var buf bytes.Buffer
- _, err = io.Copy(&buf, gz)
- gz.Close()
-
- if err != nil {
- return nil, fmt.Errorf("Read %q: %v", name, err)
- }
-
- return buf.Bytes(), nil
-}
-
-var _static_gruvbox_css = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x91\xcf\x6e\xa3\x30\x10\xc6\xef\x7e\x8a\x91\x72\xd9\x95\xa0\x8a\xa1\xa4\xc4\xb9\xec\xab\xf8\xcf\x10\x5b\xc5\x98\x35\x4e\x37\xd5\x8a\x77\x5f\x61\xa0\x01\xb7\x5d\x73\xc0\x1a\xcf\x7c\x33\xf3\xfd\x2c\x37\x1d\xfc\x25\x00\x8d\xeb\x42\xde\x70\x6b\xda\x77\x06\xd6\x75\x6e\xe8\xb9\xc4\xec\x71\xbd\x10\x00\xcb\xef\xf9\x1f\xa3\x82\x66\x50\xd6\x1e\xed\x14\xeb\xb9\x52\xa6\xbb\x32\x28\x96\x80\xe5\xfe\x6a\x3a\x06\xfc\x16\xdc\x85\x8c\x84\x30\x36\x60\x8b\x32\x18\x37\xb7\x12\x5c\xbe\x5e\xbd\xbb\x75\x8a\xc1\x41\x95\xf5\xe9\x2c\x62\x9e\x70\xea\xfd\x73\x42\x51\x4f\xdf\x24\x2c\x5d\xeb\x3c\x83\x78\x0e\x28\x94\x10\x45\xac\xeb\x3d\x26\x65\xf9\x92\x7a\x28\x65\x59\x97\xa7\xdd\x98\x74\x9e\x52\x38\xaf\xd0\x33\x38\x46\x09\x9e\x01\x67\x5c\x06\xf3\x86\xd3\xed\xcd\x0c\x26\xa0\x8a\xaa\xab\x94\xa0\xa7\xa2\x8e\x52\x5f\xf4\xa1\xaa\x38\x16\x34\x4a\x69\x9a\x81\x2e\x32\xd0\x65\x06\xfa\x39\x03\x5d\x45\x99\xd9\x95\x5c\xb8\x10\x9c\x65\xf0\x44\xa3\x5b\xd3\xd6\xad\x93\xaf\xbf\x6f\x2e\x2c\x4b\xc4\xb9\xf2\x16\x9b\xc0\x80\xf6\x77\x18\x5c\x6b\x14\x1c\x84\xe2\x78\x2e\xb7\xfe\x1e\x9f\x2a\xb4\x40\x8f\xfd\x7d\xb7\xdf\x36\x3c\x12\xf2\xcb\xa2\x32\x1c\x7e\xf4\x1e\x1b\xf4\xc3\x3c\x71\x3e\x48\x8d\x16\x19\xb4\xe6\xaa\xc3\xcf\xd8\x78\x6a\xbd\xf8\x3f\x9f\x1d\x85\x46\x34\x54\xbe\x5c\x3e\x1e\x77\x2c\x1e\x2e\x03\x8c\x24\xfe\x56\x26\xa9\xd4\x87\x63\x2b\xbf\x35\x25\xe5\xb3\x14\x3e\x28\x6d\xc4\xff\x43\x6b\x37\xdd\x86\xd9\xb7\x73\x34\xe7\xa6\x52\x2f\x3b\xf9\x6f\x08\xce\xe7\x6b\x8e\x9b\xea\x84\xe7\x76\x8f\xcf\x54\x4f\x55\x25\xab\xe7\x4b\xa2\x9e\xb2\x4d\x1c\x4a\x1f\x47\x32\x92\x7f\x01\x00\x00\xff\xff\xab\xef\x35\x5a\xc8\x03\x00\x00")
-
-func static_gruvbox_css() ([]byte, error) {
- return bindata_read(
- _static_gruvbox_css,
- "static/gruvbox.css",
- )
-}
-
-// 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 {
- return f()
- }
- return nil, fmt.Errorf("Asset %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() ([]byte, error){
- "static/gruvbox.css": static_gruvbox_css,
-}
-// 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 name := range node.Children {
- rv = append(rv, name)
- }
- return rv, nil
-}
-
-type _bintree_t struct {
- Func func() ([]byte, error)
- Children map[string]*_bintree_t
-}
-var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
- "static": &_bintree_t{nil, map[string]*_bintree_t{
- "gruvbox.css": &_bintree_t{static_gruvbox_css, map[string]*_bintree_t{
- }},
- }},
-}}
diff --git a/cmd/within.website/build.go b/cmd/within.website/build.go
index 7a7a237..ba46009 100644
--- a/cmd/within.website/build.go
+++ b/cmd/within.website/build.go
@@ -5,36 +5,57 @@ package main
import (
"context"
+ "flag"
"log"
+ "net/http"
"os"
+ "github.com/shurcooL/vfsgen"
"within.website/x/internal/kahless"
"within.website/x/internal/minipaas"
"within.website/x/internal/yeet"
)
+var (
+ genVFS = flag.Bool("gen-vfs", true, "if true, generate VFS")
+ deploy = flag.Bool("deploy", true, "if true, deploy to minipaas via kahless")
+)
+
func main() {
+ flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
- env := append(os.Environ(), []string{"CGO_ENABLED=0", "GOOS=linux"}...)
- yeet.ShouldWork(ctx, env, yeet.WD, "go", "generate")
- yeet.ShouldWork(ctx, env, yeet.WD, "go", "build", "-o=web")
- yeet.ShouldWork(ctx, env, yeet.WD, "appsluggr", "-web=web")
- fin, err := os.Open("slug.tar.gz")
- if err != nil {
- log.Fatal(err)
+ if *genVFS {
+ err := vfsgen.Generate(http.Dir("./static"), vfsgen.Options{
+ PackageName: "main",
+ BuildTags: "!dev",
+ VariableName: "assets",
+ })
+ if err != nil {
+ log.Fatalln(err)
+ }
}
- defer fin.Close()
- fname := "within.website-" + yeet.DateTag + ".tar.gz"
- pubURL, err := kahless.CopyFile(fname, fin)
- if err != nil {
- log.Fatal(err)
- }
+ if *deploy {
+ env := append(os.Environ(), []string{"CGO_ENABLED=0", "GOOS=linux"}...)
+ yeet.ShouldWork(ctx, env, yeet.WD, "go", "build", "-o=web")
+ yeet.ShouldWork(ctx, env, yeet.WD, "appsluggr", "-web=web")
+ fin, err := os.Open("slug.tar.gz")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer fin.Close()
+
+ fname := "within.website-" + yeet.DateTag + ".tar.gz"
+ pubURL, err := kahless.CopyFile(fname, fin)
+ if err != nil {
+ log.Fatal(err)
+ }
- err = minipaas.Exec("tar:from within.website " + pubURL)
- if err != nil {
- log.Fatal(err)
+ err = minipaas.Exec("tar:from within.website " + pubURL)
+ if err != nil {
+ log.Fatal(err)
+ }
}
}
diff --git a/cmd/within.website/dev.go b/cmd/within.website/dev.go
new file mode 100644
index 0000000..1417c41
--- /dev/null
+++ b/cmd/within.website/dev.go
@@ -0,0 +1,7 @@
+//+build dev
+
+package main
+
+import "net/http"
+
+var assets http.FileSystem = http.Dir("./static")
diff --git a/cmd/within.website/main.go b/cmd/within.website/main.go
index 2a5e1e2..4323dfc 100644
--- a/cmd/within.website/main.go
+++ b/cmd/within.website/main.go
@@ -6,7 +6,6 @@ import (
"flag"
"net/http"
- assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/mmikulicic/stringlist"
"within.website/ln"
"within.website/ln/ex"
@@ -76,12 +75,7 @@ func main() {
ln.Log(ctx, ln.F{"gogs_domain": *gogsDomain, "gogs_username": *gogsUsername, "gogs_repo": repo}, ln.Info("adding gogs repo"))
}
- http.Handle("/static/", http.FileServer(
- &assetfs.AssetFS{
- Asset: Asset,
- AssetDir: AssetDir,
- },
- ))
+ http.Handle("/static/", http.StripPrefix("/static", http.FileServer(assets)))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {