Use embed instead of nrsc, enables 'go get'

This commit is contained in:
Jakob Borg committed 2014-01-20 23:01:38 +01:00
1 parent 9b449cb527
commit 84d7452f9e
3 files changed
+30 -24

No files matched your search

+3 -5
View File
@@ -14,11 +14,11 @@ if [[ $fast != yes ]] ; then
fi
if [[ -z $1 ]] ; then
go build -ldflags "-X main.Version $version" \
&& nrsc syncthing gui
go build -ldflags "-X main.Version $version"
elif [[ $1 == "embed" ]] ; then
embedder main gui > gui.files.go
elif [[ $1 == "tar" ]] ; then
go build -ldflags "-X main.Version $version" \
&& nrsc syncthing gui \
&& mkdir syncthing-dist \
&& cp syncthing README.md LICENSE syncthing-dist \
&& tar zcvf syncthing-dist.tar.gz syncthing-dist \
@@ -34,7 +34,6 @@ elif [[ $1 == "all" ]] ; then
export GOARCH="$goarch"
export name="syncthing-$goos-$goarch"
go build -ldflags "-X main.Version $version" \
&& nrsc syncthing gui \
&& mkdir -p "$name" \
&& cp syncthing "$buildDir/$name" \
&& cp README.md LICENSE "$name" \
@@ -53,7 +52,6 @@ elif [[ $1 == "all" ]] ; then
export GOARCH="$goarch"
export name="syncthing-$goos-${goarch}v$goarm"
go build -ldflags "-X main.Version $version" \
&& nrsc syncthing gui \
&& mkdir -p "$name" \
&& cp syncthing "$buildDir/$name" \
&& cp README.md LICENSE "$name" \
+6
View File
@@ -0,0 +1,6 @@
package main
import "github.com/cratonica/embed"
var Resources embed.PackedResourceMap = embed.PackedResourceMap{0x1f, 0x8b, 0x8, 0x0, 0x0, 0x9, 0x6e, 0x88, 0x2, 0xff, 0xec, 0xbd, 0x7b, 0x73, 0x1b, 0x49, 0xb6, 0x27, 0xd6, 0x3d, 0x7b, 0x6d, 0xcf, 0xc0, 0x11, 0xeb, 0x71, 0x84, 0x23, 0x76, 0xfd, 0x1f, 0x58, 0x97, 0x8b, 0xae, 0x6a, 0x24, 0x41, 0x52, 0xdd, 0x77, 0x1e, 0x55, 0x2c, 0x61, 0x28, 0x8a, 0x7a, 0xb5, 0x28, 0x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 0x5d, 0xf4, 0xa2, 0xb4, 0x5e, 0xf, 0xa8, 0xeb, 0xba, 0x7f, 0x18, 0xc7, 0x69, 0xd3, 0x6b, 0xd2, 0x2b, 0x35, 0x7a, 0xc7, 0x9b, 0x52, 0x23, 0xe9, 0xde, 0x21, 0x5d, 0xc5, 0x5e, 0x3d, 0x1f, 0xa7, 0x93, 0x2c, 0x7f, 0xf3, 0xfa, 0xe9, 0xc9, 0x64, 0x34, 0x9d, 0x8c, 0xe9, 0x7d, 0xdf, 0x33, 0xc3, 0xf7, 0xe2, 0x78, 0x71,Line truncated
+21 -19
View File
@@ -3,17 +3,18 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log"
"mime"
"net/http"
"os"
"path/filepath"
"runtime"
"sync"
"time"
"bitbucket.org/tebeka/nrsc"
"github.com/calmh/syncthing/model"
"github.com/codegangsta/martini"
"github.com/cratonica/embed"
)
func startGUI(addr string, m *model.Model) {
@@ -26,9 +27,20 @@ func startGUI(addr string, m *model.Model) {
router.Get("/rest/need", restGetNeed)
router.Get("/rest/system", restGetSystem)
fs, err := embed.Unpack(Resources)
if err != nil {
panic(err)
}
var modt time.Time
fi, err := os.Stat(os.Args[0])
if err != nil {
modt = fi.ModTime()
}
go func() {
mr := martini.New()
mr.Use(nrscStatic("gui"))
mr.Use(embeddedStatic(fs, modt.UTC().Format(http.TimeFormat)))
mr.Use(martini.Recovery())
mr.Action(router.Handle)
mr.Map(m)
@@ -124,36 +136,26 @@ func restGetSystem(w http.ResponseWriter) {
json.NewEncoder(w).Encode(res)
}
func nrscStatic(path string) interface{} {
if err := nrsc.Initialize(); err != nil {
panic("Unable to initialize nrsc: " + err.Error())
}
func embeddedStatic(fs map[string][]byte, modt string) interface{} {
return func(res http.ResponseWriter, req *http.Request, log *log.Logger) {
file := req.URL.Path
// nrsc expects there not to be a leading slash
if file[0] == '/' {
file = file[1:]
}
f := nrsc.Get(file)
if f == nil {
bs, ok := fs[file]
if !ok {
return
}
rdr, err := f.Open()
if err != nil {
http.Error(res, "Internal Server Error", http.StatusInternalServerError)
}
defer rdr.Close()
mtype := mime.TypeByExtension(filepath.Ext(req.URL.Path))
if len(mtype) != 0 {
res.Header().Set("Content-Type", mtype)
}
res.Header().Set("Content-Size", fmt.Sprintf("%d", f.Size()))
res.Header().Set("Last-Modified", f.ModTime().UTC().Format(http.TimeFormat))
res.Header().Set("Content-Size", fmt.Sprintf("%d", len(bs)))
res.Header().Set("Last-Modified", modt)
io.Copy(res, rdr)
res.Write(bs)
}
}