Removed go-bindata-assetfs and replaced with statik

This commit is contained in:
Nicholas Thompson
2019-02-28 21:36:52 +02:00
committed by ncthompson
parent 790b05f90f
commit 206159cdea
13 changed files with 38 additions and 391 deletions

View File

@@ -26,7 +26,7 @@
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.PHONY: test install gofmt docker
.PHONY: test install gofmt docker statik
build:
go build ./cmd/invertergui/
@@ -48,3 +48,6 @@ vet:
docker:
docker build --tag invertergui .
statik:
statik -p=frontend -src=./frontend/root

View File

@@ -16,12 +16,7 @@ func main() {
mk2 := NewMk2Mock()
gui := webgui.NewWebGui(mk2)
rootFs := http.FileServer(frontend.BinaryFileSystem("root"))
http.Handle("/", rootFs)
jsFs := http.FileServer(frontend.BinaryFileSystem("js"))
http.Handle("/js/", http.StripPrefix("/js", jsFs))
cssFs := http.FileServer(frontend.BinaryFileSystem("css"))
http.Handle("/css/", http.StripPrefix("/css", cssFs))
http.Handle("/", frontend.NewStatic())
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
http.Handle("/munin", http.HandlerFunc(gui.ServeMuninHTTP))

View File

@@ -83,13 +83,7 @@ func main() {
gui := webgui.NewWebGui(mk2)
rootFs := http.FileServer(frontend.BinaryFileSystem("root"))
http.Handle("/", rootFs)
jsFs := http.FileServer(frontend.BinaryFileSystem("js"))
http.Handle("/js/", http.StripPrefix("/js", jsFs))
cssFs := http.FileServer(frontend.BinaryFileSystem("css"))
http.Handle("/css/", http.StripPrefix("/css", cssFs))
http.Handle("/", frontend.NewStatic())
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
http.Handle("/munin", http.HandlerFunc(gui.ServeMuninHTTP))
http.Handle("/muninconfig", http.HandlerFunc(gui.ServeMuninConfigHTTP))

View File

@@ -1,39 +1,26 @@
package frontend
import (
"net/http"
"strings"
"github.com/rakyll/statik/fs"
assetfs "github.com/elazarl/go-bindata-assetfs"
"log"
"net/http"
)
type binaryFileSystem struct {
fs http.FileSystem
type static struct {
http.FileSystem
}
func (b *binaryFileSystem) Open(name string) (http.File, error) {
return b.fs.Open(name)
}
func (b *binaryFileSystem) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
if _, err := b.fs.Open(p); err != nil {
return false
func NewStatic() http.Handler {
statikFs, err := fs.New()
if err != nil {
log.Fatal(err)
}
return true
}
return false
}
func BinaryFileSystem(root string) *binaryFileSystem {
fs := &assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
Prefix: root,
}
return &binaryFileSystem{
fs,
return &static{
FileSystem: statikFs,
}
}
func (s *static) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.FileServer(s).ServeHTTP(w, r)
}

File diff suppressed because one or more lines are too long

View File

@@ -1,2 +0,0 @@
#!/bin/bash
go-bindata-assetfs -pkg="frontend" css/ js/ root/

13
frontend/statik.go Normal file

File diff suppressed because one or more lines are too long

2
go.mod
View File

@@ -1,8 +1,8 @@
module github.com/hpdvanwyk/invertergui
require (
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/gorilla/websocket v1.4.0
github.com/mikepb/go-serial v0.0.0-20180731022703-d5134cecf05a
github.com/prometheus/client_golang v0.9.2
github.com/rakyll/statik v0.1.5
)

5
go.sum
View File

@@ -1,7 +1,5 @@
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
@@ -18,5 +16,8 @@ github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jO
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rakyll/statik v0.1.5 h1:Ly2UjURzxnsSYS0zI50fZ+srA+Fu7EbpV5hglvJvJG0=
github.com/rakyll/statik v0.1.5/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=