Skip to content

Commit

Permalink
changed from go-rice to go-embed for embedding static files
Browse files Browse the repository at this point in the history
  • Loading branch information
dh1tw committed Apr 24, 2021
1 parent 40767ba commit 9dd9630
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 50 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ VERSION := $(shell git describe --tags)
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/)

GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

all: build

build:
Expand All @@ -19,16 +22,14 @@ build:

# replace the debug version of js libraries with their production, minified versions
js-production:
find html/index.html -exec sed -i '' 's/vue.js/vue.min.js/g' {} \;
find hub/html/index.html -exec sed -i '' 's/vue.js/vue.min.js/g' {} \;

# replace the minified versions of js libraries with their full, development versions
js-development:
find html/index.html -exec sed -i '' 's/vue.min.js/vue.js/g' {} \;
find hub/html/index.html -exec sed -i '' 's/vue.min.js/vue.js/g' {} \;

generate:
go generate ./...
cd hub; \
rice embed-go

# strip off dwraf table - used for travis CI
dist:
Expand Down
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
module github.com/dh1tw/remoteRotator

go 1.15
go 1.16

require (
github.com/GeertJohan/go.rice v1.0.2
github.com/asim/go-micro/plugins/broker/nats/v3 v3.0.0-20210408173139-0d57213d3f5c
github.com/asim/go-micro/plugins/registry/nats/v3 v3.0.0-20210408173139-0d57213d3f5c
github.com/asim/go-micro/plugins/transport/nats/v3 v3.0.0-20210408173139-0d57213d3f5c
github.com/asim/go-micro/v3 v3.5.0
github.com/golang/protobuf v1.4.2
github.com/asim/go-micro/plugins/broker/nats/v3 v3.0.0-20210416163442-a91d1f7a3dbb
github.com/asim/go-micro/plugins/registry/nats/v3 v3.0.0-20210416163442-a91d1f7a3dbb
github.com/asim/go-micro/plugins/transport/nats/v3 v3.0.0-20210416163442-a91d1f7a3dbb
github.com/asim/go-micro/v3 v3.5.1
github.com/dh1tw/nolistfs v0.1.0
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/micro/mdns v0.3.0
github.com/nats-io/nats.go v1.10.0
github.com/spf13/cobra v1.1.1
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
golang.org/x/net v0.0.0-20210420210106-798c2154c571 // indirect
golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.23.0
google.golang.org/protobuf v1.26.0
)
61 changes: 31 additions & 30 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/index.html → hub/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</p>
</div>
</div>
<script src="/static/js/vue.js"></script>
<script src="/static/js/vue.min.js"></script>
<script src="/static/js/vue-resource-1.3.4.min.js"></script>
<script src="/static/js/components/rotator-name.js"></script>
<script src="/static/js/components/azimuth-rotator.js"></script>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions hub/html/static/js/vue.min.js

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions hub/hub.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package hub

import (
"embed"
"fmt"
"io/fs"
"log"
"net"
"net/http"
"regexp"
"sync"

rice "github.com/GeertJohan/go.rice"

nfs "github.com/dh1tw/nolistfs"
"github.com/dh1tw/remoteRotator/rotator"
"github.com/gorilla/mux"
)

//go:embed html
var htmlDirectory embed.FS

// Hub is a struct which makes a rotator available through network
// interfaces, supporting several protocols.
type Hub struct {
Expand Down Expand Up @@ -232,8 +236,16 @@ func (hub *Hub) ListenHTTP(host string, port int, errorCh chan<- struct{}) {

defer close(errorCh)

box := rice.MustFindBox("../html")
hub.fileServer = http.FileServer(box.HTTPBox())
webAssets, err := fs.Sub(htmlDirectory, "html")
if err != nil {
log.Println(err)
return
}

webAssetsFS := nfs.New(http.FS(webAssets))

hub.fileServer = http.FileServer(webAssetsFS)

hub.router = mux.NewRouter().StrictSlash(true)

// load the HTTP routes with their respective endpoints
Expand All @@ -242,7 +254,7 @@ func (hub *Hub) ListenHTTP(host string, port int, errorCh chan<- struct{}) {
// Listen for incoming connections.
log.Printf("listening on %s:%d for HTTP connections\n", host, port)

err := http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), hub.apiRedirectRouter(hub.router))
err = http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), hub.apiRedirectRouter(hub.router))
if err != nil {
log.Println(err)
return
Expand Down

0 comments on commit 9dd9630

Please sign in to comment.