Explorar o código

Only create assets map on demand

Jakob Borg %!s(int64=11) %!d(string=hai) anos
pai
achega
e9c7970ea4
Modificáronse 4 ficheiros con 27 adicións e 10 borrados
  1. 17 1
      auto/auto_test.go
  2. 3 4
      auto/gui.files.go
  3. 4 4
      cmd/genassets/main.go
  4. 3 1
      cmd/syncthing/gui.go

+ 17 - 1
auto/auto_test.go

@@ -4,4 +4,20 @@
 
 package auto_test
 
-// Empty test file to generate 0% coverage rather than no coverage
+import (
+	"bytes"
+	"testing"
+
+	"github.com/syncthing/syncthing/auto"
+)
+
+func TestAssets(t *testing.T) {
+	assets := auto.Assets()
+	idx, ok := assets["index.html"]
+	if !ok {
+		t.Fatal("No index.html in compiled in assets")
+	}
+	if !bytes.Contains(idx, []byte("<html")) {
+		t.Fatal("No html in index.html")
+	}
+}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 3 - 4
auto/gui.files.go


+ 4 - 4
cmd/genassets/main.go

@@ -27,17 +27,17 @@ import (
 	"io/ioutil"
 )
 
-var Assets = make(map[string][]byte)
-
-func init() {
+func Assets() map[string][]byte {
+	var assets = make(map[string][]byte, {{.assets | len}})
 	var bs []byte
 	var gr *gzip.Reader
 {{range $asset := .assets}}
 	bs, _ = base64.StdEncoding.DecodeString("{{$asset.Data}}")
 	gr, _ = gzip.NewReader(bytes.NewBuffer(bs))
 	bs, _ = ioutil.ReadAll(gr)
-	Assets["{{$asset.Name}}"] = bs
+	assets["{{$asset.Name}}"] = bs
 {{end}}
+	return assets
 }
 `))
 

+ 3 - 1
cmd/syncthing/gui.go

@@ -652,6 +652,8 @@ func validAPIKey(k string) bool {
 }
 
 func embeddedStatic(assetDir string) http.Handler {
+	assets := auto.Assets()
+
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		file := r.URL.Path
 
@@ -672,7 +674,7 @@ func embeddedStatic(assetDir string) http.Handler {
 			}
 		}
 
-		bs, ok := auto.Assets[file]
+		bs, ok := assets[file]
 		if !ok {
 			http.NotFound(w, r)
 			return

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio