Skip to content

Commit

Permalink
Utilize builtin go "embed" package to embed all static files needed b…
Browse files Browse the repository at this point in the history
…y internal viewer UI
  • Loading branch information
mapl committed Jul 31, 2021
1 parent 4ab36cc commit 1f3156c
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 44 deletions.
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/ajstarks/svgo v0.0.0-20170507103333-2489f1e6d405
github.com/akrylysov/algnhsa v0.12.1
github.com/arolek/p v0.0.0-20191103215535-df3c295ed582 // indirect
github.com/aws/aws-sdk-go v1.27.0
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/dimfeld/httptreemux v5.0.1+incompatible
github.com/gdey/bastet v0.0.0-20180226195348-314ac74cee07 // indirect
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb // indirect
github.com/gdey/tbltest v0.0.0-20170331191646-af8abc47b052
github.com/go-ini/ini v1.28.3-0.20170813052230-c787282c39ac // indirect
github.com/go-redis/redis v6.9.0+incompatible
github.com/go-spatial/cobra v0.0.3-0.20181105183926-68194e4fbcc6
github.com/go-spatial/geom v0.0.0-20190821234737-802ab2533ab4
github.com/go-test/deep v0.0.0-20170429201529-f49763a6ea0a
github.com/golang/protobuf v1.4.3
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgx v3.2.0+incompatible
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible
github.com/karalabe/xgo v0.0.0-20180416083054-f99c776585a0 // indirect
github.com/lib/pq v1.10.2 // indirect
github.com/mattn/go-sqlite3 v1.14.6
github.com/mattn/goveralls v0.0.5
github.com/pborman/uuid v1.2.0
github.com/prometheus/client_golang v1.9.0
github.com/satori/go.uuid v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/theckman/goconstraint v1.10.1-0.20180216224824-e867bde6e4e1
golang.org/x/tools v0.0.0-20200507205054-480da3ebd79c // indirect
gopkg.in/go-playground/colors.v1 v1.0.2-0.20150924111726-b53ecfb39623
Expand Down
57 changes: 28 additions & 29 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/viewer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !noViewer
// +build !noViewer,!go1.16

package server

Expand Down
3 changes: 2 additions & 1 deletion server/viewer_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package server
import (
"github.com/dimfeld/httptreemux"
"github.com/go-spatial/tegola/internal/build"
"github.com/go-spatial/tegola/observability"
)

func init() {
Expand All @@ -14,4 +15,4 @@ func init() {

// setupViewer in this file is used for removing the viewer routes when the
// build flag `noViewer` is set
func setupViewer(group *httptreemux.Group) {}
func setupViewer(o observability.Interface, group *httptreemux.Group) {}
19 changes: 19 additions & 0 deletions server/viewer_embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build !noViewer,go1.16

package server

import (
"net/http"

"github.com/dimfeld/httptreemux"
"github.com/go-spatial/tegola/observability"
"github.com/go-spatial/tegola/ui"
)

// setupViewer in this file is used for registering the viewer routes when the viewer
// is included in the build (default)
func setupViewer(o observability.Interface, group *httptreemux.Group) {

group.UsingContext().Handler(observability.InstrumentViewerHandler(http.MethodGet, "/", o, http.FileServer(ui.GetDistFileSystem())))
group.UsingContext().Handler(observability.InstrumentViewerHandler(http.MethodGet, "/*path", o, http.FileServer(ui.GetDistFileSystem())))
}
Empty file added ui/dist/.keep
Empty file.
21 changes: 21 additions & 0 deletions ui/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ui

import (
"embed"
"io/fs"
"net/http"

"github.com/go-spatial/tegola/internal/log"
)

//Embed UI dist Folder recursively
//go:embed dist/*
var dist embed.FS

func GetDistFileSystem() http.FileSystem {
distfs, err := fs.Sub(dist, "dist")
if err != nil {
log.Fatal(err)
}
return http.FS(distfs)
}
19 changes: 11 additions & 8 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/ajstarks/svgo
# github.com/akrylysov/algnhsa v0.12.1
## explicit
github.com/akrylysov/algnhsa
# github.com/arolek/p v0.0.0-20191103215535-df3c295ed582
## explicit
# github.com/aws/aws-lambda-go v1.13.3
github.com/aws/aws-lambda-go/events
github.com/aws/aws-lambda-go/lambda
Expand Down Expand Up @@ -64,18 +66,14 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
github.com/beorn7/perks/quantile
# github.com/cespare/xxhash/v2 v2.1.1
github.com/cespare/xxhash/v2
# github.com/cockroachdb/apd v1.1.0
## explicit
# github.com/dimfeld/httptreemux v5.0.1+incompatible
## explicit
github.com/dimfeld/httptreemux
# github.com/gdey/bastet v0.0.0-20180226195348-314ac74cee07
## explicit
# github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb
## explicit
# github.com/gdey/tbltest v0.0.0-20170331191646-af8abc47b052
## explicit
github.com/gdey/tbltest
# github.com/go-ini/ini v1.28.3-0.20170813052230-c787282c39ac
## explicit
# github.com/go-redis/redis v6.9.0+incompatible
## explicit
github.com/go-redis/redis
Expand Down Expand Up @@ -113,8 +111,9 @@ github.com/golang/protobuf/ptypes/timestamp
# github.com/google/uuid v1.0.0
github.com/google/uuid
# github.com/inconshreveable/mousetrap v1.0.0
## explicit
github.com/inconshreveable/mousetrap
# github.com/jackc/fake v0.0.0-20150926172116-812a484cc733
## explicit
# github.com/jackc/pgx v3.2.0+incompatible
## explicit
github.com/jackc/pgx
Expand All @@ -129,7 +128,7 @@ github.com/jmespath/go-jmespath
## explicit
github.com/jteeuwen/go-bindata
github.com/jteeuwen/go-bindata/go-bindata
# github.com/karalabe/xgo v0.0.0-20180416083054-f99c776585a0
# github.com/lib/pq v1.10.2
## explicit
# github.com/mattn/go-sqlite3 v1.14.6
## explicit
Expand Down Expand Up @@ -160,6 +159,10 @@ github.com/prometheus/common/model
github.com/prometheus/procfs
github.com/prometheus/procfs/internal/fs
github.com/prometheus/procfs/internal/util
# github.com/satori/go.uuid v1.2.0
## explicit
# github.com/shopspring/decimal v1.2.0
## explicit
# github.com/spf13/pflag v1.0.1
github.com/spf13/pflag
# github.com/theckman/goconstraint v1.10.1-0.20180216224824-e867bde6e4e1
Expand Down

0 comments on commit 1f3156c

Please sign in to comment.