Browse Source

embed static resources via statik

Chris Lu 6 years ago
parent
commit
fffbc2d490

File diff suppressed because it is too large
+ 0 - 69
weed/images/favicon.go


+ 8 - 12
weed/server/common.go

@@ -12,21 +12,24 @@ import (
 	"time"
 
 	"github.com/chrislusf/seaweedfs/weed/glog"
-	"github.com/chrislusf/seaweedfs/weed/images"
 	"github.com/chrislusf/seaweedfs/weed/operation"
 	"github.com/chrislusf/seaweedfs/weed/security"
 	"github.com/chrislusf/seaweedfs/weed/stats"
 	"github.com/chrislusf/seaweedfs/weed/storage"
 	"github.com/chrislusf/seaweedfs/weed/util"
+
+	_ "github.com/chrislusf/seaweedfs/weed/statik"
+	statik "github.com/rakyll/statik/fs"
 )
 
 var serverStats *stats.ServerStats
 var startTime = time.Now()
+var statikFS http.FileSystem
 
 func init() {
 	serverStats = stats.NewServerStats()
 	go serverStats.Start()
-
+	statikFS, _ = statik.New()
 }
 
 func writeJson(w http.ResponseWriter, r *http.Request, httpStatus int, obj interface{}) (err error) {
@@ -191,14 +194,7 @@ func statsMemoryHandler(w http.ResponseWriter, r *http.Request) {
 	writeJsonQuiet(w, r, http.StatusOK, m)
 }
 
-func faviconHandler(w http.ResponseWriter, r *http.Request) {
-	data, err := images.Asset("favicon/favicon.ico")
-	if err != nil {
-		glog.V(2).Infoln("favicon read error:", err)
-		return
-	}
-
-	if e := writeResponseContent("favicon.ico", "image/x-icon", bytes.NewReader(data), w, r); e != nil {
-		glog.V(2).Infoln("response write error:", e)
-	}
+func handleStaticResources(defaultMux *http.ServeMux) {
+	defaultMux.Handle("/favicon.ico", http.FileServer(statikFS))
+	defaultMux.Handle("/seaweedfsstatic/", http.StripPrefix("/seaweedfsstatic", http.FileServer(statikFS)))
 }

+ 4 - 3
weed/server/filer_server.go

@@ -37,6 +37,7 @@ type FilerServer struct {
 }
 
 func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) (fs *FilerServer, err error) {
+
 	fs = &FilerServer{
 		option: option,
 	}
@@ -56,7 +57,7 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
 
 	notification.LoadConfiguration(v.Sub("notification"))
 
-	defaultMux.HandleFunc("/favicon.ico", faviconHandler)
+	handleStaticResources(defaultMux)
 	defaultMux.HandleFunc("/", fs.filerHandler)
 	if defaultMux != readonlyMux {
 		readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
@@ -85,8 +86,8 @@ func LoadConfiguration(configFileName string, required bool) {
 			glog.Errorf("Failed to load %s.toml file from current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/"+
 				"\n\nPlease follow this example and add a filer.toml file to "+
 				"current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/:\n"+
-				"    https://github.com/chrislusf/seaweedfs/blob/master/weed/%s.toml\n" +
-				"\n\nOr use this command to generate the default toml file\n" +
+				"    https://github.com/chrislusf/seaweedfs/blob/master/weed/%s.toml\n"+
+				"\n\nOr use this command to generate the default toml file\n"+
 				"    weed scaffold -config=%s -output=.\n",
 				configFileName, configFileName, configFileName)
 		}

+ 1 - 1
weed/server/filer_ui/templates.go

@@ -44,7 +44,7 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
 	<div class="container">
 		<div class="page-header">
 			<h1>
-				<img src="http://7viirv.com1.z0.glb.clouddn.com/seaweed50x50.png"></img>
+				<img src="/seaweedfsstatic/seaweed50x50.png"></img>
 				SeaweedFS Filer
 			</h1>
 		</div>

+ 1 - 1
weed/server/master_ui/templates.go

@@ -15,7 +15,7 @@ var StatusTpl = template.Must(template.New("status").Parse(`<!DOCTYPE html>
     <div class="container">
       <div class="page-header">
 	    <h1>
-	      <img src="http://7viirv.com1.z0.glb.clouddn.com/seaweed50x50.png"></img>
+	      <img src="/seaweedfsstatic/seaweed50x50.png"></img>
           SeaweedFS <small>{{ .Version }}</small>
 	    </h1>
       </div>

+ 2 - 1
weed/server/volume_server.go

@@ -43,6 +43,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
 
 	vs.guard = security.NewGuard(whiteList, "")
 
+	handleStaticResources(adminMux)
 	adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
 	adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
 	adminMux.HandleFunc("/admin/assign_volume", vs.guard.WhiteList(vs.assignVolumeHandler))
@@ -64,7 +65,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
 	adminMux.HandleFunc("/", vs.privateStoreHandler)
 	if publicMux != adminMux {
 		// separated admin and public port
-		publicMux.HandleFunc("/favicon.ico", faviconHandler)
+		handleStaticResources(publicMux)
 		publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
 	}
 

+ 1 - 1
weed/server/volume_server_ui/templates.go

@@ -50,7 +50,7 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
     <div class="container">
       <div class="page-header">
 	    <h1>
-	      <img src="http://7viirv.com1.z0.glb.clouddn.com/seaweed50x50.png"></img>
+	      <img src="/seaweedfsstatic/seaweed50x50.png"></img>
           SeaweedFS <small>{{ .Version }}</small>
 	    </h1>
       </div>

+ 0 - 0
weed/images/favicon/favicon.ico → weed/static/favicon.ico


BIN
weed/static/seaweed50x50.png


File diff suppressed because it is too large
+ 10 - 0
weed/statik/statik.go


Some files were not shown because too many files changed in this diff