Use simple script for asset embedding

This commit is contained in:
Jakob Borg 2014-02-23 13:54:23 +01:00
parent 5837277f8d
commit d0863d495c
4 changed files with 12970 additions and 13 deletions

27
assets.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
cat <<EOT
package auto
import "compress/gzip"
import "bytes"
import "io/ioutil"
var Assets = make(map[string][]byte)
func init() {
var data []byte
var gr *gzip.Reader
EOT
cd gui
for f in $(find . -type f) ; do
f="${f#./}"
echo "gr, _ = gzip.NewReader(bytes.NewBuffer([]byte{"
gzip -c $f | od -vt x1 | sed 's/^[0-9a-f]*//' | sed 's/\([0-9a-f][0-9a-f]\)/0x\1,/g'
echo "}))"
echo "data, _ = ioutil.ReadAll(gr)"
echo "Assets[\"$f\"] = data"
done
echo "}"

File diff suppressed because one or more lines are too long

View File

@ -6,15 +6,13 @@ version=$(git describe --always)
buildDir=dist
if [[ $fast != yes ]] ; then
./assets.sh | gofmt > auto/gui.files.go
go get -d
go test ./...
fi
if [[ -z $1 ]] ; then
go build -ldflags "-X main.Version $version"
elif [[ $1 == "embed" ]] ; then
embedder auto gui > auto/gui.files.go \
&& go build -ldflags "-X main.Version $version"
elif [[ $1 == "tar" ]] ; then
go build -ldflags "-X main.Version $version" \
&& mkdir syncthing-dist \

View File

@ -11,15 +11,9 @@ import (
"time"
"github.com/calmh/syncthing/auto"
"github.com/cratonica/embed"
)
func embeddedStatic() interface{} {
fs, err := embed.Unpack(auto.Resources)
if err != nil {
panic(err)
}
var modt = time.Now().UTC().Format(http.TimeFormat)
return func(res http.ResponseWriter, req *http.Request, log *log.Logger) {
@ -29,7 +23,7 @@ func embeddedStatic() interface{} {
file = file[1:]
}
bs, ok := fs[file]
bs, ok := auto.Assets[file]
if !ok {
return
}