Statically compile templates in the final binary (#84)

This commit is contained in:
konrad 2019-07-11 19:10:42 +00:00 committed by Gitea
parent 1f1a079fd3
commit 50ca8bd28e
30 changed files with 1405 additions and 15 deletions

View File

@ -29,6 +29,7 @@ steps:
environment:
GOFLAGS: '-mod=vendor'
commands:
- make generate
- make lint
- make fmt-check
# - make got-swag # Commented out until we figured out how to get this working on drone
@ -148,6 +149,7 @@ steps:
pull: true
commands:
- export PATH=$PATH:$GOPATH/bin
- make generate
- make release-dirs
- name: static-build-windows
@ -353,6 +355,7 @@ steps:
image: techknowlogick/xgo:latest
pull: true
commands:
- make generate
- make release-dirs
- name: static-build-windows

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ debian/
logs/
docs/public/
docs/resources/
pkg/static/templates_vfsdata.go

View File

@ -17,7 +17,7 @@ WORKDIR ${GOPATH}/src/code.vikunja.io/api
#Checkout version if set
RUN if [ -n "${VIKUNJA_VERSION}" ]; then git checkout "${VIKUNJA_VERSION}"; fi \
&& make clean build
&& make clean generate build
###################
# The actual image
@ -27,7 +27,6 @@ FROM alpine:3.9
LABEL maintainer="maintainers@vikunja.io"
WORKDIR /app/vikunja/
COPY --from=build-env /go/src/code.vikunja.io/api/templates ./templates
COPY --from=build-env /go/src/code.vikunja.io/api/vikunja .
RUN chown nobody:nogroup -R /app/vikunja
ENV VIKUNJA_SERVICE_ROOTPATH=/app/vikunja/

View File

@ -95,6 +95,10 @@ fmt-check:
.PHONY: build
build: $(EXECUTABLE)
.PHONY: generate
generate:
go generate code.vikunja.io/api/pkg/static
$(EXECUTABLE): $(SOURCES)
go build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
@ -147,8 +151,6 @@ release-compress:
.PHONY: release-copy
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
mkdir $(DIST)/release/templates -p
cp templates/ $(DIST)/templates/ -R
.PHONY: release-check
release-check:
@ -156,7 +158,7 @@ release-check:
.PHONY: release-os-package
release-os-package:
$(foreach file,$(filter-out %.sha256,$(wildcard $(DIST)/release/$(EXECUTABLE)-*)),mkdir $(file)-full;mv $(file) $(file)-full/; mv $(file).sha256 $(file)-full/; cp config.yml.sample $(file)-full/config.yml; cp $(DIST)/release/templates $(file)-full/ -R; cp LICENSE $(file)-full/; )
$(foreach file,$(filter-out %.sha256,$(wildcard $(DIST)/release/$(EXECUTABLE)-*)),mkdir $(file)-full;mv $(file) $(file)-full/; mv $(file).sha256 $(file)-full/; cp config.yml.sample $(file)-full/config.yml; cp LICENSE $(file)-full/; )
.PHONY: release-zip
release-zip:
@ -165,7 +167,7 @@ release-zip:
# Builds a deb package using fpm from a previously created binary (using make build)
.PHONY: build-deb
build-deb:
fpm -s dir -t deb --url https://vikunja.io -n vikunja -v $(PKGVERSION) --license GPLv3 --directories /opt/vikunja --after-install ./build/after-install.sh --description 'Vikunja is an open-source todo application, written in Go. It lets you create lists,tasks and share them via teams or directly between users.' -m maintainers@vikunja.io ./$(BINLOCATION)=/opt/vikunja/vikunja ./templates=/opt/vikunja ./config.yml.sample=/etc/vikunja/config.yml;
fpm -s dir -t deb --url https://vikunja.io -n vikunja -v $(PKGVERSION) --license GPLv3 --directories /opt/vikunja --after-install ./build/after-install.sh --description 'Vikunja is an open-source todo application, written in Go. It lets you create lists,tasks and share them via teams or directly between users.' -m maintainers@vikunja.io ./$(BINLOCATION)=/opt/vikunja/vikunja ./config.yml.sample=/etc/vikunja/config.yml;
.PHONY: reprepro
reprepro:

View File

@ -59,3 +59,10 @@ which will build a vikunja binary into the working directory. Writing test cases
is highly encouraged and helps developers sleep at night.
Thats it! You are ready to hack on Vikunja. Test changes, push them to the repository, and open a pull request.
## Static assets
Each Vikunja release contains all static assets directly compiled into the binary.
To prevent this during development, use the `dev` tag when developing.
See the [make docs](make.md#statically-compile-all-templates-into-the-binary) about how to compile with static assets for a release.

View File

@ -22,6 +22,7 @@ These tasks are automatically run in our CI every time someone pushes to master
* `make ineffassign-check`
* `make misspell-check`
* `make goconst-check`
* `make generate`
* `make build`
### clean
@ -64,6 +65,14 @@ make build
Builds a `vikunja`-binary in the root directory of the repo for the platform it is run on.
### Statically compile all templates into the binary
{{< highlight bash >}}
make generate
{{< /highlight >}}
This generates static code with all templates, meaning no template need to be referenced at runtime.
### Compress the built binary
{{< highlight bash >}}

2
go.mod
View File

@ -56,6 +56,8 @@ require (
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/prometheus/client_golang v0.9.2
github.com/samedi/caldav-go v3.0.0+incompatible
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/jwalterweatherman v1.1.0 // indirect

4
go.sum
View File

@ -203,6 +203,10 @@ github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b h1:4kg1wyftSKxLtnPAvcRWakIPpokB9w780/KwrNLnfPA=
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=

View File

@ -19,10 +19,12 @@ package mail
import (
"bytes"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/static"
"code.vikunja.io/api/pkg/utils"
"github.com/labstack/gommon/log"
"github.com/shurcooL/httpfs/html/vfstemplate"
"gopkg.in/gomail.v2"
"text/template"
"html/template"
)
// Opts holds infos for a mail
@ -84,8 +86,10 @@ func SendMailWithTemplate(to, subject, tpl string, data map[string]interface{})
var htmlContent bytes.Buffer
var plainContent bytes.Buffer
t := &Template{
Templates: template.Must(template.ParseGlob(config.ServiceRootpath.GetString() + "/templates/mail/*.tmpl")),
t, err := vfstemplate.ParseGlob(static.Templates, nil, "*.tmpl")
if err != nil {
log.Log.Errorf("SendMailWithTemplate: ParseGlob: %v", err)
return
}
boundary := "np" + utils.MakeRandomString(13)
@ -93,13 +97,13 @@ func SendMailWithTemplate(to, subject, tpl string, data map[string]interface{})
data["Boundary"] = boundary
data["FrontendURL"] = config.ServiceFrontendurl.GetString()
if err := t.Templates.ExecuteTemplate(&htmlContent, tpl+".html.tmpl", data); err != nil {
log.Error(3, "Template: %v", err)
if err := t.ExecuteTemplate(&htmlContent, tpl+".html.tmpl", data); err != nil {
log.Log.Errorf("ExecuteTemplate: %v", err)
return
}
if err := t.Templates.ExecuteTemplate(&plainContent, tpl+".plain.tmpl", data); err != nil {
log.Error(3, "Template: %v", err)
if err := t.ExecuteTemplate(&plainContent, tpl+".plain.tmpl", data); err != nil {
log.Log.Errorf("ExecuteTemplate: %v", err)
return
}

21
pkg/static/static.go Normal file
View File

@ -0,0 +1,21 @@
// Vikunja is a todo-list application to facilitate your life.
// Copyright 2019 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//go:generate go run -tags=dev templates_generate.go
package static
// The single purpose of this file is to invoke the generation of static files

23
pkg/static/templates.go Normal file
View File

@ -0,0 +1,23 @@
// Vikunja is a todo-list application to facilitate your life.
// Copyright 2019 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// +build dev
package static
import "net/http"
var Templates http.FileSystem = http.Dir(`templates/mail`)

View File

@ -0,0 +1,37 @@
// Vikunja is a todo-list application to facilitate your life.
// Copyright 2019 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// +build ignore
package main
import (
"log"
"net/http"
"github.com/shurcooL/vfsgen"
)
func main() {
err := vfsgen.Generate(http.Dir(`../../templates/mail`), vfsgen.Options{
PackageName: "static",
BuildTags: "!dev",
VariableName: "Templates",
})
if err != nil {
log.Fatalln(err)
}
}

View File

@ -4,4 +4,4 @@ Welcome to Vikunja!
To confirm you email address, click the link below:
{{.User.EmailConfirmToken}}
{{.FrontendURL}}?userEmailConfirm={{.User.EmailConfirmToken}}

View File

@ -31,4 +31,6 @@ import (
_ "github.com/jgautheron/goconst/cmd/goconst"
_ "honnef.co/go/tools/cmd/staticcheck"
_ "github.com/shurcooL/vfsgen"
)

21
vendor/github.com/shurcooL/httpfs/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2015 Dmitri Shuralyov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,73 @@
// Package vfstemplate offers html/template helpers that use http.FileSystem.
package vfstemplate
import (
"fmt"
"html/template"
"net/http"
"path"
"github.com/shurcooL/httpfs/path/vfspath"
"github.com/shurcooL/httpfs/vfsutil"
)
// ParseFiles creates a new Template if t is nil and parses the template definitions from
// the named files. The returned template's name will have the (base) name and
// (parsed) contents of the first file. There must be at least one file.
// If an error occurs, parsing stops and the returned *Template is nil.
func ParseFiles(fs http.FileSystem, t *template.Template, filenames ...string) (*template.Template, error) {
return parseFiles(fs, t, filenames...)
}
// ParseGlob parses the template definitions in the files identified by the
// pattern and associates the resulting templates with t. The pattern is
// processed by vfspath.Glob and must match at least one file. ParseGlob is
// equivalent to calling t.ParseFiles with the list of files matched by the
// pattern.
func ParseGlob(fs http.FileSystem, t *template.Template, pattern string) (*template.Template, error) {
filenames, err := vfspath.Glob(fs, pattern)
if err != nil {
return nil, err
}
if len(filenames) == 0 {
return nil, fmt.Errorf("vfs/html/vfstemplate: pattern matches no files: %#q", pattern)
}
return parseFiles(fs, t, filenames...)
}
// parseFiles is the helper for the method and function. If the argument
// template is nil, it is created from the first file.
func parseFiles(fs http.FileSystem, t *template.Template, filenames ...string) (*template.Template, error) {
if len(filenames) == 0 {
// Not really a problem, but be consistent.
return nil, fmt.Errorf("vfs/html/vfstemplate: no files named in call to ParseFiles")
}
for _, filename := range filenames {
b, err := vfsutil.ReadFile(fs, filename)
if err != nil {
return nil, err
}
s := string(b)
name := path.Base(filename)
// First template becomes return value if not already defined,
// and we use that one for subsequent New calls to associate
// all the templates together. Also, if this file has the same name
// as t, this file becomes the contents of t, so
// t, err := New(name).Funcs(xxx).ParseFiles(name)
// works. Otherwise we create a new template associated with t.
var tmpl *template.Template
if t == nil {
t = template.New(name)
}
if name == t.Name() {
tmpl = t
} else {
tmpl = t.New(name)
}
_, err = tmpl.Parse(s)
if err != nil {
return nil, err
}
}
return t, nil
}

105
vendor/github.com/shurcooL/httpfs/path/vfspath/match.go generated vendored Normal file
View File

@ -0,0 +1,105 @@
// Package vfspath implements utility routines for manipulating virtual file system paths.
package vfspath
import (
"net/http"
"os"
"path"
"sort"
"strings"
"github.com/shurcooL/httpfs/vfsutil"
)
const separator = "/"
// Glob returns the names of all files matching pattern or nil
// if there is no matching file. The syntax of patterns is the same
// as in path.Match. The pattern may describe hierarchical names such as
// /usr/*/bin/ed.
//
// Glob ignores file system errors such as I/O errors reading directories.
// The only possible returned error is ErrBadPattern, when pattern
// is malformed.
func Glob(fs http.FileSystem, pattern string) (matches []string, err error) {
if !hasMeta(pattern) {
if _, err = vfsutil.Stat(fs, pattern); err != nil {
return nil, nil
}
return []string{pattern}, nil
}
dir, file := path.Split(pattern)
switch dir {
case "":
dir = "."
case string(separator):
// nothing
default:
dir = dir[0 : len(dir)-1] // chop off trailing separator
}
if !hasMeta(dir) {
return glob(fs, dir, file, nil)
}
var m []string
m, err = Glob(fs, dir)
if err != nil {
return
}
for _, d := range m {
matches, err = glob(fs, d, file, matches)
if err != nil {
return
}
}
return
}
// glob searches for files matching pattern in the directory dir
// and appends them to matches. If the directory cannot be
// opened, it returns the existing matches. New matches are
// added in lexicographical order.
func glob(fs http.FileSystem, dir, pattern string, matches []string) (m []string, e error) {
m = matches
fi, err := vfsutil.Stat(fs, dir)
if err != nil {
return
}
if !fi.IsDir() {
return
}
fis, err := vfsutil.ReadDir(fs, dir)
if err != nil {
return
}
sort.Sort(byName(fis))
for _, fi := range fis {
n := fi.Name()
matched, err := path.Match(path.Clean(pattern), n)
if err != nil {
return m, err
}
if matched {
m = append(m, path.Join(dir, n))
}
}
return
}
// hasMeta reports whether path contains any of the magic characters
// recognized by Match.
func hasMeta(path string) bool {
// TODO(niemeyer): Should other magic characters be added here?
return strings.ContainsAny(path, "*?[")
}
// byName implements sort.Interface.
type byName []os.FileInfo
func (f byName) Len() int { return len(f) }
func (f byName) Less(i, j int) bool { return f[i].Name() < f[j].Name() }
func (f byName) Swap(i, j int) { f[i], f[j] = f[j], f[i] }

21
vendor/github.com/shurcooL/httpfs/vfsutil/file.go generated vendored Normal file
View File

@ -0,0 +1,21 @@
package vfsutil
import (
"net/http"
"os"
)
// File implements http.FileSystem using the native file system restricted to a
// specific file served at root.
//
// While the FileSystem.Open method takes '/'-separated paths, a File's string
// value is a filename on the native file system, not a URL, so it is separated
// by filepath.Separator, which isn't necessarily '/'.
type File string
func (f File) Open(name string) (http.File, error) {
if name != "/" {
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
return os.Open(string(f))
}

39
vendor/github.com/shurcooL/httpfs/vfsutil/vfsutil.go generated vendored Normal file
View File

@ -0,0 +1,39 @@
// Package vfsutil implements some I/O utility functions for http.FileSystem.
package vfsutil
import (
"io/ioutil"
"net/http"
"os"
)
// ReadDir reads the contents of the directory associated with file and
// returns a slice of FileInfo values in directory order.
func ReadDir(fs http.FileSystem, name string) ([]os.FileInfo, error) {
f, err := fs.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
return f.Readdir(0)
}
// Stat returns the FileInfo structure describing file.
func Stat(fs http.FileSystem, name string) (os.FileInfo, error) {
f, err := fs.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
return f.Stat()
}
// ReadFile reads the file named by path from fs and returns the contents.
func ReadFile(fs http.FileSystem, path string) ([]byte, error) {
rc, err := fs.Open(path)
if err != nil {
return nil, err
}
defer rc.Close()
return ioutil.ReadAll(rc)
}

146
vendor/github.com/shurcooL/httpfs/vfsutil/walk.go generated vendored Normal file
View File

@ -0,0 +1,146 @@
package vfsutil
import (
"io"
"net/http"
"os"
pathpkg "path"
"path/filepath"
"sort"
)
// Walk walks the filesystem rooted at root, calling walkFn for each file or
// directory in the filesystem, including root. All errors that arise visiting files
// and directories are filtered by walkFn. The files are walked in lexical
// order.
func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error {
info, err := Stat(fs, root)
if err != nil {
return walkFn(root, nil, err)
}
return walk(fs, root, info, walkFn)
}
// readDirNames reads the directory named by dirname and returns
// a sorted list of directory entries.
func readDirNames(fs http.FileSystem, dirname string) ([]string, error) {
fis, err := ReadDir(fs, dirname)
if err != nil {
return nil, err
}
names := make([]string, len(fis))
for i := range fis {
names[i] = fis[i].Name()
}
sort.Strings(names)
return names, nil
}
// walk recursively descends path, calling walkFn.
func walk(fs http.FileSystem, path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
err := walkFn(path, info, nil)
if err != nil {
if info.IsDir() && err == filepath.SkipDir {
return nil
}
return err
}
if !info.IsDir() {
return nil
}
names, err := readDirNames(fs, path)
if err != nil {
return walkFn(path, info, err)
}
for _, name := range names {
filename := pathpkg.Join(path, name)
fileInfo, err := Stat(fs, filename)
if err != nil {
if err := walkFn(filename, fileInfo, err); err != nil && err != filepath.SkipDir {
return err
}
} else {
err = walk(fs, filename, fileInfo, walkFn)
if err != nil {
if !fileInfo.IsDir() || err != filepath.SkipDir {
return err
}
}
}
}
return nil
}
// WalkFilesFunc is the type of the function called for each file or directory visited by WalkFiles.
// It's like filepath.WalkFunc, except it provides an additional ReadSeeker parameter for file being visited.
type WalkFilesFunc func(path string, info os.FileInfo, rs io.ReadSeeker, err error) error
// WalkFiles walks the filesystem rooted at root, calling walkFn for each file or
// directory in the filesystem, including root. In addition to FileInfo, it passes an
// ReadSeeker to walkFn for each file it visits.
func WalkFiles(fs http.FileSystem, root string, walkFn WalkFilesFunc) error {
file, info, err := openStat(fs, root)
if err != nil {
return walkFn(root, nil, nil, err)
}
return walkFiles(fs, root, info, file, walkFn)
}
// walkFiles recursively descends path, calling walkFn.
// It closes the input file after it's done with it, so the caller shouldn't.
func walkFiles(fs http.FileSystem, path string, info os.FileInfo, file http.File, walkFn WalkFilesFunc) error {
err := walkFn(path, info, file, nil)
file.Close()
if err != nil {
if info.IsDir() && err == filepath.SkipDir {
return nil
}
return err
}
if !info.IsDir() {
return nil
}
names, err := readDirNames(fs, path)
if err != nil {
return walkFn(path, info, nil, err)
}
for _, name := range names {
filename := pathpkg.Join(path, name)
file, fileInfo, err := openStat(fs, filename)
if err != nil {
if err := walkFn(filename, nil, nil, err); err != nil && err != filepath.SkipDir {
return err
}
} else {
err = walkFiles(fs, filename, fileInfo, file, walkFn)
// file is closed by walkFiles, so we don't need to close it here.
if err != nil {
if !fileInfo.IsDir() || err != filepath.SkipDir {
return err
}
}
}
}
return nil
}
// openStat performs Open and Stat and returns results, or first error encountered.
// The caller is responsible for closing the returned file when done.
func openStat(fs http.FileSystem, name string) (http.File, os.FileInfo, error) {
f, err := fs.Open(name)
if err != nil {
return nil, nil, err
}
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, nil, err
}
return f, fi, nil
}

16
vendor/github.com/shurcooL/vfsgen/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,16 @@
sudo: false
language: go
go:
- 1.x
- master
matrix:
allow_failures:
- go: master
fast_finish: true
install:
- # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step).
script:
- go get -t -v ./...
- diff -u <(echo -n) <(gofmt -d -s .)
- go tool vet .
- go test -v -race ./...

10
vendor/github.com/shurcooL/vfsgen/CONTRIBUTING.md generated vendored Normal file
View File

@ -0,0 +1,10 @@
Contributing
============
vfsgen is open source, thanks for considering contributing!
Please note that vfsgen aims to be simple and minimalistic, with as little to configure as possible. If you'd like to remove or simplify code (while having tests continue to pass), fix bugs, or improve code (e.g., add missing error checking, etc.), PRs and issues are welcome.
However, if you'd like to add new functionality that increases complexity or scope, please make an issue and discuss your proposal first. I'm unlikely to accept such changes outright. It might be that your request is already a part of other similar packages, or it might fit in their scope better. See [Comparison and Alternatives](https://github.com/shurcooL/vfsgen/tree/README-alternatives-and-comparison-section#comparison) sections.
Thank you!

21
vendor/github.com/shurcooL/vfsgen/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2015 Dmitri Shuralyov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

201
vendor/github.com/shurcooL/vfsgen/README.md generated vendored Normal file
View File

@ -0,0 +1,201 @@
vfsgen
======
[![Build Status](https://travis-ci.org/shurcooL/vfsgen.svg?branch=master)](https://travis-ci.org/shurcooL/vfsgen) [![GoDoc](https://godoc.org/github.com/shurcooL/vfsgen?status.svg)](https://godoc.org/github.com/shurcooL/vfsgen)
Package vfsgen takes an http.FileSystem (likely at `go generate` time) and
generates Go code that statically implements the provided http.FileSystem.
Features:
- Efficient generated code without unneccessary overhead.
- Uses gzip compression internally (selectively, only for files that compress well).
- Enables direct access to internal gzip compressed bytes via an optional interface.
- Outputs `gofmt`ed Go code.
Installation
------------
```bash
go get -u github.com/shurcooL/vfsgen
```
Usage
-----
Package `vfsgen` is a Go code generator library. It has a `Generate` function that takes an input filesystem (as a [`http.FileSystem`](https://godoc.org/net/http#FileSystem) type), and generates a Go code file that statically implements the contents of the input filesystem.
For example, we can use [`http.Dir`](https://godoc.org/net/http#Dir) as a `http.FileSystem` implementation that uses the contents of the `/path/to/assets` directory:
```Go
var fs http.FileSystem = http.Dir("/path/to/assets")
```
Now, when you execute the following code:
```Go
err := vfsgen.Generate(fs, vfsgen.Options{})
if err != nil {
log.Fatalln(err)
}
```
An assets_vfsdata.go file will be generated in the current directory:
```Go
// Code generated by vfsgen; DO NOT EDIT.
package main
import ...
// assets statically implements the virtual filesystem provided to vfsgen.Generate.
var assets http.FileSystem = ...
```
Then, in your program, you can use `assets` as any other [`http.FileSystem`](https://godoc.org/net/http#FileSystem), for example:
```Go
file, err := assets.Open("/some/file.txt")
if err != nil {
return err
}
defer file.Close()
```
```Go
http.Handle("/assets/", http.FileServer(assets))
```
`vfsgen` can be more useful when combined with build tags and go generate directives. This is described below.
### `go generate` Usage
vfsgen is great to use with go generate directives. The code invoking `vfsgen.Generate` can go in an assets_generate.go file, which can then be invoked via "//go:generate go run assets_generate.go". The input virtual filesystem can read directly from disk, or it can be more involved.
By using build tags, you can create a development mode where assets are loaded directly from disk via `http.Dir`, but then statically implemented for final releases.
For example, suppose your source filesystem is defined in a package with import path "example.com/project/data" as:
```Go
// +build dev
package data
import "net/http"
// Assets contains project assets.
var Assets http.FileSystem = http.Dir("assets")
```
When built with the "dev" build tag, accessing `data.Assets` will read from disk directly via `http.Dir`.
A generate helper file assets_generate.go can be invoked via "//go:generate go run -tags=dev assets_generate.go" directive:
```Go
// +build ignore
package main
import (
"log"
"example.com/project/data"
"github.com/shurcooL/vfsgen"
)
func main() {
err := vfsgen.Generate(data.Assets, vfsgen.Options{
PackageName: "data",
BuildTags: "!dev",
VariableName: "Assets",
})
if err != nil {
log.Fatalln(err)
}
}
```
Note that "dev" build tag is used to access the source filesystem, and the output file will contain "!dev" build tag. That way, the statically implemented version will be used during normal builds and `go get`, when custom builds tags are not specified.
### `vfsgendev` Usage
`vfsgendev` is a binary that can be used to replace the need for the assets_generate.go file.
Make sure it's installed and available in your PATH.
```bash
go get -u github.com/shurcooL/vfsgen/cmd/vfsgendev
```
Then the "//go:generate go run -tags=dev assets_generate.go" directive can be replaced with:
```
//go:generate vfsgendev -source="example.com/project/data".Assets
```
vfsgendev accesses the source variable using "dev" build tag, and generates an output file with "!dev" build tag.
### Additional Embedded Information
All compressed files implement [`httpgzip.GzipByter` interface](https://godoc.org/github.com/shurcooL/httpgzip#GzipByter) for efficient direct access to the internal compressed bytes:
```Go
// GzipByter is implemented by compressed files for
// efficient direct access to the internal compressed bytes.
type GzipByter interface {
// GzipBytes returns gzip compressed contents of the file.
GzipBytes() []byte
}
```
Files that have been determined to not be worth gzip compressing (their compressed size is larger than original) implement [`httpgzip.NotWorthGzipCompressing` interface](https://godoc.org/github.com/shurcooL/httpgzip#NotWorthGzipCompressing):
```Go
// NotWorthGzipCompressing is implemented by files that were determined
// not to be worth gzip compressing (the file size did not decrease as a result).
type NotWorthGzipCompressing interface {
// NotWorthGzipCompressing is a noop. It's implemented in order to indicate
// the file is not worth gzip compressing.
NotWorthGzipCompressing()
}
```
Comparison
----------
vfsgen aims to be conceptually simple to use. The [`http.FileSystem`](https://godoc.org/net/http#FileSystem) abstraction is central to vfsgen. It's used as both input for code generation, and as output in the generated code.
That enables great flexibility through orthogonality, since helpers and wrappers can operate on `http.FileSystem` without knowing about vfsgen. If you want, you can perform pre-processing, minifying assets, merging folders, filtering out files and otherwise modifying input via generic `http.FileSystem` middleware.
It avoids unneccessary overhead by merging what was previously done with two distinct packages into a single package.
It strives to be the best in its class in terms of code quality and efficiency of generated code. However, if your use goals are different, there are other similar packages that may fit your needs better.
### Alternatives
- [`go-bindata`](https://github.com/jteeuwen/go-bindata) - Reads from disk, generates Go code that provides access to data via a [custom API](https://github.com/jteeuwen/go-bindata#accessing-an-asset).
- [`go-bindata-assetfs`](https://github.com/elazarl/go-bindata-assetfs) - Takes output of go-bindata and provides a wrapper that implements `http.FileSystem` interface (the same as what vfsgen outputs directly).
- [`becky`](https://github.com/tv42/becky) - Embeds assets as string literals in Go source.
- [`statik`](https://github.com/rakyll/statik) - Embeds a directory of static files to be accessed via `http.FileSystem` interface (sounds very similar to vfsgen); implementation sourced from [camlistore](https://camlistore.org).
- [`go.rice`](https://github.com/GeertJohan/go.rice) - Makes working with resources such as HTML, JS, CSS, images and templates very easy.
- [`esc`](https://github.com/mjibson/esc) - Embeds files into Go programs and provides `http.FileSystem` interfaces to them.
- [`staticfiles`](https://github.com/bouk/staticfiles) - Allows you to embed a directory of files into your Go binary.
- [`togo`](https://github.com/flazz/togo) - Generates a Go source file with a `[]byte` var containing the given file's contents.
- [`fileb0x`](https://github.com/UnnoTed/fileb0x) - Simple customizable tool to embed files in Go.
- [`embedfiles`](https://github.com/leighmcculloch/embedfiles) - Simple tool for embedding files in Go code as a map.
- [`packr`](https://github.com/gobuffalo/packr) - Simple solution for bundling static assets inside of Go binaries.
- [`rsrc`](https://github.com/akavel/rsrc) - Tool for embedding .ico & manifest resources in Go programs for Windows.
Attribution
-----------
This package was originally based on the excellent work by [@jteeuwen](https://github.com/jteeuwen) on [`go-bindata`](https://github.com/jteeuwen/go-bindata) and [@elazarl](https://github.com/elazarl) on [`go-bindata-assetfs`](https://github.com/elazarl/go-bindata-assetfs).
License
-------
- [MIT License](LICENSE)

45
vendor/github.com/shurcooL/vfsgen/commentwriter.go generated vendored Normal file
View File

@ -0,0 +1,45 @@
package vfsgen
import "io"
// commentWriter writes a Go comment to the underlying io.Writer,
// using line comment form (//).
type commentWriter struct {
W io.Writer
wroteSlashes bool // Wrote "//" at the beginning of the current line.
}
func (c *commentWriter) Write(p []byte) (int, error) {
var n int
for i, b := range p {
if !c.wroteSlashes {
s := "//"
if b != '\n' {
s = "// "
}
if _, err := io.WriteString(c.W, s); err != nil {
return n, err
}
c.wroteSlashes = true
}
n0, err := c.W.Write(p[i : i+1])
n += n0
if err != nil {
return n, err
}
if b == '\n' {
c.wroteSlashes = false
}
}
return len(p), nil
}
func (c *commentWriter) Close() error {
if !c.wroteSlashes {
if _, err := io.WriteString(c.W, "//"); err != nil {
return err
}
c.wroteSlashes = true
}
return nil
}

15
vendor/github.com/shurcooL/vfsgen/doc.go generated vendored Normal file
View File

@ -0,0 +1,15 @@
/*
Package vfsgen takes an http.FileSystem (likely at `go generate` time) and
generates Go code that statically implements the provided http.FileSystem.
Features:
- Efficient generated code without unneccessary overhead.
- Uses gzip compression internally (selectively, only for files that compress well).
- Enables direct access to internal gzip compressed bytes via an optional interface.
- Outputs `gofmt`ed Go code.
*/
package vfsgen

485
vendor/github.com/shurcooL/vfsgen/generator.go generated vendored Normal file
View File

@ -0,0 +1,485 @@
package vfsgen
import (
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
pathpkg "path"
"sort"
"strconv"
"text/template"
"time"
"github.com/shurcooL/httpfs/vfsutil"
)
// Generate Go code that statically implements input filesystem,
// write the output to a file specified in opt.
func Generate(input http.FileSystem, opt Options) error {
opt.fillMissing()
// Use an in-memory buffer to generate the entire output.
buf := new(bytes.Buffer)
err := t.ExecuteTemplate(buf, "Header", opt)
if err != nil {
return err
}
var toc toc
err = findAndWriteFiles(buf, input, &toc)
if err != nil {
return err
}
err = t.ExecuteTemplate(buf, "DirEntries", toc.dirs)
if err != nil {
return err
}
err = t.ExecuteTemplate(buf, "Trailer", toc)
if err != nil {
return err
}
// Write output file (all at once).
fmt.Println("writing", opt.Filename)
err = ioutil.WriteFile(opt.Filename, buf.Bytes(), 0644)
return err
}
type toc struct {
dirs []*dirInfo
HasCompressedFile bool // There's at least one compressedFile.
HasFile bool // There's at least one uncompressed file.
}
// fileInfo is a definition of a file.
type fileInfo struct {
Path string
Name string
ModTime time.Time
UncompressedSize int64
}
// dirInfo is a definition of a directory.
type dirInfo struct {
Path string
Name string
ModTime time.Time
Entries []string
}
// findAndWriteFiles recursively finds all the file paths in the given directory tree.
// They are added to the given map as keys. Values will be safe function names
// for each file, which will be used when generating the output code.
func findAndWriteFiles(buf *bytes.Buffer, fs http.FileSystem, toc *toc) error {
walkFn := func(path string, fi os.FileInfo, r io.ReadSeeker, err error) error {
if err != nil {
// Consider all errors reading the input filesystem as fatal.
return err
}
switch fi.IsDir() {
case false:
file := &fileInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
UncompressedSize: fi.Size(),
}
marker := buf.Len()
// Write CompressedFileInfo.
err = writeCompressedFileInfo(buf, file, r)
switch err {
default:
return err
case nil:
toc.HasCompressedFile = true
// If compressed file is not smaller than original, revert and write original file.
case errCompressedNotSmaller:
_, err = r.Seek(0, io.SeekStart)
if err != nil {
return err
}
buf.Truncate(marker)
// Write FileInfo.
err = writeFileInfo(buf, file, r)
if err != nil {
return err
}
toc.HasFile = true
}
case true:
entries, err := readDirPaths(fs, path)
if err != nil {
return err
}
dir := &dirInfo{
Path: path,
Name: pathpkg.Base(path),
ModTime: fi.ModTime().UTC(),
Entries: entries,
}
toc.dirs = append(toc.dirs, dir)
// Write DirInfo.
err = t.ExecuteTemplate(buf, "DirInfo", dir)
if err != nil {
return err
}
}
return nil
}
err := vfsutil.WalkFiles(fs, "/", walkFn)
return err
}
// readDirPaths reads the directory named by dirname and returns
// a sorted list of directory paths.
func readDirPaths(fs http.FileSystem, dirname string) ([]string, error) {
fis, err := vfsutil.ReadDir(fs, dirname)
if err != nil {
return nil, err
}
paths := make([]string, len(fis))
for i := range fis {
paths[i] = pathpkg.Join(dirname, fis[i].Name())
}
sort.Strings(paths)
return paths, nil
}
// writeCompressedFileInfo writes CompressedFileInfo.
// It returns errCompressedNotSmaller if compressed file is not smaller than original.
func writeCompressedFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
err := t.ExecuteTemplate(w, "CompressedFileInfo-Before", file)
if err != nil {
return err
}
sw := &stringWriter{Writer: w}
gw := gzip.NewWriter(sw)
_, err = io.Copy(gw, r)
if err != nil {
return err
}
err = gw.Close()
if err != nil {
return err
}
if sw.N >= file.UncompressedSize {
return errCompressedNotSmaller
}
err = t.ExecuteTemplate(w, "CompressedFileInfo-After", file)
return err
}
var errCompressedNotSmaller = errors.New("compressed file is not smaller than original")
// Write FileInfo.
func writeFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
err := t.ExecuteTemplate(w, "FileInfo-Before", file)
if err != nil {
return err
}
sw := &stringWriter{Writer: w}
_, err = io.Copy(sw, r)
if err != nil {
return err
}
err = t.ExecuteTemplate(w, "FileInfo-After", file)
return err
}
var t = template.Must(template.New("").Funcs(template.FuncMap{
"quote": strconv.Quote,
"comment": func(s string) (string, error) {
var buf bytes.Buffer
cw := &commentWriter{W: &buf}
_, err := io.WriteString(cw, s)
if err != nil {
return "", err
}
err = cw.Close()
return buf.String(), err
},
}).Parse(`{{define "Header"}}// Code generated by vfsgen; DO NOT EDIT.
{{with .BuildTags}}// +build {{.}}
{{end}}package {{.PackageName}}
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
pathpkg "path"
"time"
)
{{comment .VariableComment}}
var {{.VariableName}} = func() http.FileSystem {
fs := vfsgen۰FS{
{{end}}
{{define "CompressedFileInfo-Before"}} {{quote .Path}}: &vfsgen۰CompressedFileInfo{
name: {{quote .Name}},
modTime: {{template "Time" .ModTime}},
uncompressedSize: {{.UncompressedSize}},
{{/* This blank line separating compressedContent is neccessary to prevent potential gofmt issues. See issue #19. */}}
compressedContent: []byte("{{end}}{{define "CompressedFileInfo-After"}}"),
},
{{end}}
{{define "FileInfo-Before"}} {{quote .Path}}: &vfsgen۰FileInfo{
name: {{quote .Name}},
modTime: {{template "Time" .ModTime}},
content: []byte("{{end}}{{define "FileInfo-After"}}"),
},
{{end}}
{{define "DirInfo"}} {{quote .Path}}: &vfsgen۰DirInfo{
name: {{quote .Name}},
modTime: {{template "Time" .ModTime}},
},
{{end}}
{{define "DirEntries"}} }
{{range .}}{{if .Entries}} fs[{{quote .Path}}].(*vfsgen۰DirInfo).entries = []os.FileInfo{{"{"}}{{range .Entries}}
fs[{{quote .}}].(os.FileInfo),{{end}}
}
{{end}}{{end}}
return fs
}()
{{end}}
{{define "Trailer"}}
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) {{"{"}}{{if .HasCompressedFile}}
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{{end}}{{if .HasFile}}
case *vfsgen۰FileInfo:
return &vfsgen۰File{
vfsgen۰FileInfo: f,
Reader: bytes.NewReader(f.content),
}, nil{{end}}
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))
}
}
{{if .HasCompressedFile}}
// 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()
}
{{else}}
// We already imported "compress/gzip" and "io/ioutil", but ended up not using them. Avoid unused import error.
var _ = gzip.Reader{}
var _ = ioutil.Discard
{{end}}{{if .HasFile}}
// vfsgen۰FileInfo is a static definition of an uncompressed file (because it's not worth gzip compressing).
type vfsgen۰FileInfo struct {
name string
modTime time.Time
content []byte
}
func (f *vfsgen۰FileInfo) Readdir(count int) ([]os.FileInfo, error) {
return nil, fmt.Errorf("cannot Readdir from file %s", f.name)
}
func (f *vfsgen۰FileInfo) Stat() (os.FileInfo, error) { return f, nil }
func (f *vfsgen۰FileInfo) NotWorthGzipCompressing() {}
func (f *vfsgen۰FileInfo) Name() string { return f.name }
func (f *vfsgen۰FileInfo) Size() int64 { return int64(len(f.content)) }
func (f *vfsgen۰FileInfo) Mode() os.FileMode { return 0444 }
func (f *vfsgen۰FileInfo) ModTime() time.Time { return f.modTime }
func (f *vfsgen۰FileInfo) IsDir() bool { return false }
func (f *vfsgen۰FileInfo) Sys() interface{} { return nil }
// vfsgen۰File is an opened file instance.
type vfsgen۰File struct {
*vfsgen۰FileInfo
*bytes.Reader
}
func (f *vfsgen۰File) Close() error {
return nil
}
{{else if not .HasCompressedFile}}
// We already imported "bytes", but ended up not using it. Avoid unused import error.
var _ = bytes.Reader{}
{{end}}
// 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
}
{{end}}
{{define "Time"}}
{{- if .IsZero -}}
time.Time{}
{{- else -}}
time.Date({{.Year}}, {{printf "%d" .Month}}, {{.Day}}, {{.Hour}}, {{.Minute}}, {{.Second}}, {{.Nanosecond}}, time.UTC)
{{- end -}}
{{end}}
`))

45
vendor/github.com/shurcooL/vfsgen/options.go generated vendored Normal file
View File

@ -0,0 +1,45 @@
package vfsgen
import (
"fmt"
"strings"
)
// Options for vfsgen code generation.
type Options struct {
// Filename of the generated Go code output (including extension).
// If left empty, it defaults to "{{toLower .VariableName}}_vfsdata.go".
Filename string
// PackageName is the name of the package in the generated code.
// If left empty, it defaults to "main".
PackageName string
// BuildTags are the optional build tags in the generated code.
// The build tags syntax is specified by the go tool.
BuildTags string
// VariableName is the name of the http.FileSystem variable in the generated code.
// If left empty, it defaults to "assets".
VariableName string
// VariableComment is the comment of the http.FileSystem variable in the generated code.
// If left empty, it defaults to "{{.VariableName}} statically implements the virtual filesystem provided to vfsgen.".
VariableComment string
}
// fillMissing sets default values for mandatory options that are left empty.
func (opt *Options) fillMissing() {
if opt.PackageName == "" {
opt.PackageName = "main"
}
if opt.VariableName == "" {
opt.VariableName = "assets"
}
if opt.Filename == "" {
opt.Filename = fmt.Sprintf("%s_vfsdata.go", strings.ToLower(opt.VariableName))
}
if opt.VariableComment == "" {
opt.VariableComment = fmt.Sprintf("%s statically implements the virtual filesystem provided to vfsgen.", opt.VariableName)
}
}

27
vendor/github.com/shurcooL/vfsgen/stringwriter.go generated vendored Normal file
View File

@ -0,0 +1,27 @@
package vfsgen
import (
"io"
)
// stringWriter writes given bytes to underlying io.Writer as a Go interpreted string literal value,
// not including double quotes. It tracks the total number of bytes written.
type stringWriter struct {
io.Writer
N int64 // Total bytes written.
}
func (sw *stringWriter) Write(p []byte) (n int, err error) {
const hex = "0123456789abcdef"
buf := []byte{'\\', 'x', 0, 0}
for _, b := range p {
buf[2], buf[3] = hex[b/16], hex[b%16]
_, err = sw.Writer.Write(buf)
if err != nil {
return n, err
}
n++
sw.N++
}
return n, nil
}

6
vendor/modules.txt vendored
View File

@ -143,6 +143,12 @@ github.com/samedi/caldav-go/global
github.com/samedi/caldav-go/handlers
github.com/samedi/caldav-go/files
github.com/samedi/caldav-go/ixml
# github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b
github.com/shurcooL/httpfs/html/vfstemplate
github.com/shurcooL/httpfs/vfsutil
github.com/shurcooL/httpfs/path/vfspath
# github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/shurcooL/vfsgen
# github.com/spf13/afero v1.2.2
github.com/spf13/afero
github.com/spf13/afero/mem