Skip to content

Commit

Permalink
nsqadmin: new flag --dev-static-dir instead of debug build tag
Browse files Browse the repository at this point in the history
avoid hard-coded ../../nsqadmin/static/build in debug build,
more flexible and obvious this way
  • Loading branch information
ploxiln committed Sep 12, 2021
1 parent 52b9143 commit 2e99e51
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
1 change: 1 addition & 0 deletions apps/nsqadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func nsqadminFlagSet(opts *nsqadmin.Options) *flag.FlagSet {

flagSet.String("http-address", opts.HTTPAddress, "<addr>:<port> to listen on for HTTP clients")
flagSet.String("base-path", opts.BasePath, "URL base path")
flagSet.String("dev-static-dir", opts.DevStaticDir, "(development use only)")

flagSet.String("graphite-url", opts.GraphiteURL, "graphite HTTP address")
flagSet.Bool("proxy-graphite", false, "proxy HTTP requests to graphite")
Expand Down
4 changes: 3 additions & 1 deletion nsqadmin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ Read the [docs](https://nsq.io/components/nsqadmin.html)
### Dependencies

1. Install NodeJS 16.x (includes `npm`)
2. Install [`go-bindata`](https://github.com/shuLhan/go-bindata) (for "legacy" go < 1.16)

### Live Reload Workflow

1. `$ npm install`
2. `$ ./gulp --series clean watch`
3. `$ go build --tags debug` (from `apps/nsqadmin` directory)
3. `$ cd .. && make && ./build/nsqadmin --dev-static-dir=nsqadmin/static/build --lookupd-http-address=<...>`
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. `$ go-bindata --pkg=nsqadmin --prefix=static/build/ static/build/...` (for "legacy" go < 1.16)
28 changes: 21 additions & 7 deletions nsqadmin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func NewSingleHostReverseProxy(target *url.URL, connectTimeout time.Duration, re
}

type httpServer struct {
nsqadmin *NSQAdmin
router http.Handler
client *http_api.Client
ci *clusterinfo.ClusterInfo
basePath string
nsqadmin *NSQAdmin
router http.Handler
client *http_api.Client
ci *clusterinfo.ClusterInfo
basePath string
devStaticDir string
}

func NewHTTPServer(nsqadmin *NSQAdmin) *httpServer {
Expand All @@ -66,12 +67,15 @@ func NewHTTPServer(nsqadmin *NSQAdmin) *httpServer {
router.PanicHandler = http_api.LogPanicHandler(nsqadmin.logf)
router.NotFound = http_api.LogNotFoundHandler(nsqadmin.logf)
router.MethodNotAllowed = http_api.LogMethodNotAllowedHandler(nsqadmin.logf)

s := &httpServer{
nsqadmin: nsqadmin,
router: router,
client: client,
ci: clusterinfo.New(nsqadmin.logf, client),
basePath: nsqadmin.getOpts().BasePath,

basePath: nsqadmin.getOpts().BasePath,
devStaticDir: nsqadmin.getOpts().DevStaticDir,
}

bp := func(p string) string {
Expand Down Expand Up @@ -164,7 +168,17 @@ 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 := staticAsset(assetName)
var (
asset []byte
err error
)
if s.devStaticDir != "" {
s.nsqadmin.logf(LOG_DEBUG, "using dev dir %q for static asset %q", s.devStaticDir, assetName)
fsPath := path.Join(s.devStaticDir, assetName)
asset, err = ioutil.ReadFile(fsPath)
} else {
asset, err = staticAsset(assetName)
}
if err != nil {
return nil, http_api.Err{404, "NOT_FOUND"}
}
Expand Down
2 changes: 2 additions & 0 deletions nsqadmin/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Options struct {
HTTPAddress string `flag:"http-address"`
BasePath string `flag:"base-path"`

DevStaticDir string `flag:"dev-static-dir"`

GraphiteURL string `flag:"graphite-url"`
ProxyGraphite bool `flag:"proxy-graphite"`

Expand Down
4 changes: 2 additions & 2 deletions nsqadmin/static.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.16 && !debug
// +build go1.16,!debug
//go:build go1.16
// +build go1.16

package nsqadmin

Expand Down
19 changes: 0 additions & 19 deletions nsqadmin/static_debug.go

This file was deleted.

0 comments on commit 2e99e51

Please sign in to comment.