Skip to content

Commit

Permalink
Embed resource files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoern Rabenstein committed May 20, 2014
1 parent d5a6271 commit 9763d47
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pushgateway
.deps
*.test
*~
bindata.go
29 changes: 27 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2014 Prometheus Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION := 0.0.1

TARGET := pushgateway
Expand Down Expand Up @@ -48,9 +61,21 @@ $(GOLIB):
dependencies:
$(GO) get -d

$(BINARY): $(GOCC) $(GOLIB) dependencies
$(BINARY): $(GOCC) $(GOLIB) dependencies bindata.go
$(GO) build $(BUILDFLAGS) -o $@

bindata.go: $(GOPATH)/bin/go-bindata resources/*
$(GOPATH)/bin/go-bindata resources/

bindata-debug: $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -debug resources/

bindata-embed: $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata resources/

$(GOPATH)/bin/go-bindata:
$(GO) get github.com/jteeuwen/go-bindata/...

$(ARCHIVE): $(BINARY)
tar -czf $@ bin/

Expand All @@ -75,4 +100,4 @@ rmproper: clean
rm -rf .deps
rm -rf $(ARCHIVE)

.PHONY: test tag dependencies clean release upload
.PHONY: test tag dependencies clean release upload bindata-debug bindata-embed
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,22 @@ have successfully sent a `DELETE` request and then send a `PUT`, it is
guaranteed that the `DELETE` will be processed first (and vice versa).

Deleting non-existing metrics is a no-op and will not result in an
error.
error.

## Development

The normal binary embeds the files in `resources`. For development
purposes, it is handy to have a running binary use those files
directly (so that you can see the effect of changes immediately). To
switch to direct usage, type `make bindata-debug` just before
compiling the binary. Switch back to "normal" mode by typing `make
bindata-embed`. (Just `make` after a resource has changed will result
in the same.)

## Contributing

Relevant style guidelines are the [Go Code Review
Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments)
and the _Formatting and style_ section of Peter Bourgon's [Go:
Best Practices for Production
Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style).
9 changes: 8 additions & 1 deletion handler/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ func (_ data) FormatTimestamp(ts int64) string {

func Status(
ms storage.MetricStore,
assetFunc func(string) ([]byte, error),
flags map[string]string,
buildInfo map[string]string,
) func(http.ResponseWriter) {
birth := time.Now()
return func(w http.ResponseWriter) {
t, err := template.ParseFiles("handler/template.html")
t := template.New("status")
tpl, err := assetFunc("resources/template.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
_, err = t.Parse(string(tpl))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func main() {
m.Put("/metrics/jobs/:job", handler.Push(ms))
m.Post("/metrics/jobs/:job", handler.Push(ms))
m.Delete("/metrics/jobs/:job", handler.Delete(ms))
statusHandler := handler.Status(ms, flags, BuildInfo)
m.Get("/functions.js", func() ([]byte, error) { return Asset("resources/functions.js") })
statusHandler := handler.Status(ms, Asset, flags, BuildInfo)
m.Get("/status", statusHandler)
m.Get("/", statusHandler)

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 9763d47

Please sign in to comment.