Skip to content

Commit

Permalink
nsqadmin: use go:embed on go 1.16+
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Aug 16, 2021
1 parent 88986b8 commit b20f230
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nsqio/nsq

go 1.13
go 1.16

require (
github.com/BurntSushi/toml v0.3.1
Expand Down
20 changes: 10 additions & 10 deletions nsqadmin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ administrative tasks.
Read the [docs](https://nsq.io/components/nsqadmin.html)


## Local Development
## Local Development (Go 1.16+)

### Dependencies

1. Install [`go-bindata`](https://github.com/shuLhan/go-bindata)
2. Install NodeJS 14.x (includes npm)
1. Install NodeJS 16.x (includes `npm`)

### Workflow
### Live Reload Workflow

1. `$ npm install`
2. `$ ./gulp --series clean watch` or `$ ./gulp --series clean build`
3. `$ go-bindata --debug --pkg=nsqadmin --prefix=static/build/ static/build/...`
4. `$ go build ../apps/nsqadmin && ./nsqadmin`
5. make changes (repeat step 4 only if you make changes to any Go code)
6. `$ go-bindata --pkg=nsqadmin --prefix=static/build/ static/build/...`
7. commit other changes and `bindata.go`
2. `$ ./gulp --series clean watch`
3. `$ go build --tags debug` (from `apps/nsqadmin` directory)
4. make changes to static assets (repeat step 3 only if you make changes to any Go code)

### Build

1. `$ ./gulp --series clean build`
2 changes: 1 addition & 1 deletion nsqadmin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request, ps h
func (s *httpServer) staticAssetHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) (interface{}, error) {
assetName := ps.ByName("asset")

asset, err := Asset(assetName)
asset, err := staticAsset(assetName)
if err != nil {
return nil, http_api.Err{404, "NOT_FOUND"}
}
Expand Down
15 changes: 15 additions & 0 deletions nsqadmin/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build go1.16
// +build !debug

package nsqadmin

import (
"embed"
)

//go:embed static/build
var static embed.FS

func staticAsset(name string) ([]byte, error) {
return static.ReadFile("static/build/" + name)
}
19 changes: 19 additions & 0 deletions nsqadmin/static_debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build go1.16
// +build debug

package nsqadmin

import (
"io/ioutil"
"os"
"path"
)

func staticAsset(name string) ([]byte, error) {
path := path.Join("../../nsqadmin/static/build", name)
_, err := os.Stat(path)
if err != nil {
return nil, err
}
return ioutil.ReadFile(path)
}
7 changes: 7 additions & 0 deletions nsqadmin/static_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !go1.16

package nsqadmin

func staticAsset(name string) ([]byte, error) {
return Asset(name)
}

0 comments on commit b20f230

Please sign in to comment.