mirror of https://github.com/prometheus/prometheus
- utility/embed-static.sh, get called in Makefile to create go map from files - web/blob/blob.go implements http Handle for serving the files from the map - web/status.go uses blog.GetFile() to get the template file The assets are gzipped and decompressed on demand.pull/87/head
parent
2192b52064
commit
fc16580b4c
@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
cat <<EOF
|
||||
package blob
|
||||
var files = map [string] map [string] []byte {
|
||||
EOF
|
||||
|
||||
type_file=`tempfile`
|
||||
cat <<EOF > $type_file
|
||||
var types = map [string] map [string] string {
|
||||
EOF
|
||||
|
||||
|
||||
for dir in $@
|
||||
do
|
||||
pushd "$dir" > /dev/null
|
||||
echo -e "\t\"`basename $dir`\": {"
|
||||
echo -e "\t\"`basename $dir`\": {" >> $type_file
|
||||
|
||||
find -type f | while read file
|
||||
do
|
||||
mime=`mimetype -b "$file"`
|
||||
name=`echo "$file"|sed 's|\.\/||'`
|
||||
echo -e "\t\t\"$name\": \"$mime\"," >> $type_file
|
||||
|
||||
echo -e "\t\t\"$name\": {"
|
||||
gzip -9 -c "$file" | xxd -p |sed 's/\(..\)/0x\1, /g'
|
||||
echo -e "\t\t},"
|
||||
echo
|
||||
done
|
||||
echo -e "\t}," >> $type_file
|
||||
echo -e "\t},"
|
||||
popd > /dev/null
|
||||
done
|
||||
echo '}'
|
||||
cat $type_file
|
||||
echo '}'
|
||||
rm $type_file
|
@ -0,0 +1,43 @@
|
||||
package blob
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetFile(bucket string, name string) ([]byte, error) {
|
||||
reader := bytes.NewReader(files[bucket][name])
|
||||
gz, err := gzip.NewReader(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
io.Copy(&b, gz)
|
||||
gz.Close()
|
||||
|
||||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
type Handler struct{}
|
||||
|
||||
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.URL.String()
|
||||
if name == "" {
|
||||
name = "index.html"
|
||||
}
|
||||
|
||||
file, err := GetFile("static", name)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Printf("Could not get file: %s", err)
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", types["static"][name])
|
||||
w.Write(file)
|
||||
}
|
Loading…
Reference in new issue