diff --git a/Dockerfile b/Dockerfile index 5f6d5988..858318d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ FROM gcr.io/distroless/static:latest LABEL maintainer "Stackdriver Engineering " COPY stackdriver-prometheus-sidecar /bin/stackdriver-prometheus-sidecar -COPY cmd/stackdriver-prometheus-sidecar/statusz-tmpl.html /statusz-tmpl.html EXPOSE 9091 ENTRYPOINT [ "/bin/stackdriver-prometheus-sidecar" ] diff --git a/cmd/stackdriver-prometheus-sidecar/statik/statik.go b/cmd/stackdriver-prometheus-sidecar/statik/statik.go new file mode 100644 index 00000000..8e3b7c9e --- /dev/null +++ b/cmd/stackdriver-prometheus-sidecar/statik/statik.go @@ -0,0 +1,12 @@ +// Code generated by statik. DO NOT EDIT. + +package statik + +import ( + "github.com/rakyll/statik/fs" +) + +func init() { + data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\xb6^BP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x00 \x00statusz-tmpl.htmlUT\x05\x00\x01H\xb86^\xb4Xoo\xdb\xb6\x13~\xdfOq\xbf\xfc:\xa0\x05\x12+ 0`p\x15\x0fi\xfe-\x88\xdb\x19I\xddb/i\xf1$q\x95H\x83<\xa7\xcd\x04}\xf7\x81\x7f,\xc9\xb2\xecf\xc1\x06\x040\xc9\xe7\xee!\xef\xb9\xe3\xd1N\xfc\xbf\xcb\xdf/>\xfd1\xbb\x82\x9c\xcab\xf2*\xf6\x1f\x00q\x8e\x8c\xdb\x01@L\x82\n\x9c<\x10\xa3\x95\x81Ti\xa8\xaa\xd1\x03\xeaG\xd4\x1fY\x89u\x1dG\xde\xc2[\x1bzZ\x8f\x01\x16\x8a?A\x15&\x00\xa9\x92t\x94\xb2R\x14Oc0L\x9a#\x83Z\xa4\xef\x82A\x1d>\xf3\x93\x8eOR \xd3cX(\xca\xdf5\x8b\xdf\x04\xa7|\x0c'\xc7\xc7?\xb5\x8b\x84\xdf\xe9\x88\x15\"\x93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&K\xa2\xd1\xd8T\x13r\xb8\x9d\x99\x1e\xcd}\x03\xde\xce\xf6E\xf8\xe5|:\x1c\xd6\x97\xf3\xe9\xeeh\xe2(t\xdf\xd0\xc3O'\xe7Y\xa61s\x17\xd0\xc4Q~: \xad\xdb~\x01\xe9b\xe1\xa9\x19\xee\xde\xfe\xe5\x08\xa7\xc8'%\xa3$o:q\xe7\xf0U\xa5\x99\xcc\x10^{\x87\xc3\xf5 t\xff\xf1\xd9\xe0\x9e\xeb}lx\xc1a\x1dXw-\\\xc1\x0fa\xf3\x01\xed\xbaof\xa3D\x00\xdc\x17)7\x91J\xe2\xab\xaey\xa3\x95\xbf\xa2\xa0\xddC\xb4\xa5\x96G\xef=\xb8W\xaeT\xab\xb2\x11\x8b\xd4n\x99\xac\xe1!\xbc&\xe5\xa4\x19\xda`C\x1bk\xbe\xa9\x0c\xa9\xff@\x06\xfb\x13F$P\"1\xce\x88\xf5u\xf0\xf0\x87\x80\xfe\x93\xba\xa1\xa7%6\x93\x95\x14\xb4S\x99\xe1M\xbab\x04\xb56\xe4\x08k\x9f\x9e\x96\xb8\xb9\xfe\x99\x15+\xec.\xffKju&q\xe4\x7f\x07\xc6\x91\xffo\xc2\xdf\x01\x00\x00\xff\xffPK\x07\x08Tmx%\xa7\x04\x00\x00e\x10\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\xb6^BPTmx%\xa7\x04\x00\x00e\x10\x00\x00\x11\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00statusz-tmpl.htmlUT\x05\x00\x01H\xb86^PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00H\x00\x00\x00\xef\x04\x00\x00\x00\x00" + fs.Register(data) +} diff --git a/cmd/stackdriver-prometheus-sidecar/statusz.go b/cmd/stackdriver-prometheus-sidecar/statusz.go index 1dc04e49..df105e15 100644 --- a/cmd/stackdriver-prometheus-sidecar/statusz.go +++ b/cmd/stackdriver-prometheus-sidecar/statusz.go @@ -11,23 +11,28 @@ // 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. + +//go:generate statik -f -src=./ -include=*.html package main import ( "html/template" + "io/ioutil" "net/http" "os" "path/filepath" "time" + _ "github.com/Stackdriver/stackdriver-prometheus-sidecar/cmd/stackdriver-prometheus-sidecar/statik" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/prometheus/common/version" + "github.com/rakyll/statik/fs" ) var ( serverStart = time.Now() - statuszTmpl = template.Must(template.ParseFiles("statusz-tmpl.html")) + statuszTmpl *template.Template ) type statuszHandler struct { @@ -36,6 +41,25 @@ type statuszHandler struct { cfg *mainConfig } +func init() { + statikFS, err := fs.New() + if err != nil { + panic(err) + } + statuszFile, err := statikFS.Open("/statusz-tmpl.html") + if err != nil { + panic(err) + } + contents, err := ioutil.ReadAll(statuszFile) + if err != nil { + panic(err) + } + statuszTmpl, err = template.New("statusz-tmpl.html").Parse(string(contents)) + if err != nil { + panic(err) + } +} + func (h *statuszHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var data struct { ServerName string diff --git a/go.mod b/go.mod index 0ce6ee33..779a775f 100644 --- a/go.mod +++ b/go.mod @@ -60,6 +60,7 @@ require ( github.com/prometheus/procfs v0.0.3 // indirect github.com/prometheus/prometheus v0.0.0-20190710134608-e5b22494857d github.com/prometheus/tsdb v0.10.0 + github.com/rakyll/statik v0.1.6 github.com/rogpeppe/go-internal v1.5.0 // indirect github.com/samuel/go-zookeeper v0.0.0-20190801204459-3c104360edc8 // indirect github.com/shopspring/decimal v0.0.0-20191125035519-b054a8dfd10d // indirect diff --git a/go.sum b/go.sum index 002ba4b5..24508ebb 100644 --- a/go.sum +++ b/go.sum @@ -474,6 +474,8 @@ github.com/prometheus/prometheus v0.0.0-20190710134608-e5b22494857d/go.mod h1:11 github.com/prometheus/tsdb v0.9.1/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4= github.com/prometheus/tsdb v0.10.0 h1:If5rVCMTp6W2SiRAQFlbpJNgVlgMEd+U2GZckwK38ic= github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4= +github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs= +github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rlmcpherson/s3gof3r v0.5.0/go.mod h1:s7vv7SMDPInkitQMuZzH615G7yWHdrU2r/Go7Bo71Rs= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= diff --git a/vendor/github.com/rakyll/statik/LICENSE b/vendor/github.com/rakyll/statik/LICENSE new file mode 100644 index 00000000..a4c5efd8 --- /dev/null +++ b/vendor/github.com/rakyll/statik/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014 Google Inc. + + 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. diff --git a/vendor/github.com/rakyll/statik/fs/fs.go b/vendor/github.com/rakyll/statik/fs/fs.go new file mode 100644 index 00000000..345aa002 --- /dev/null +++ b/vendor/github.com/rakyll/statik/fs/fs.go @@ -0,0 +1,216 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// 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. + +// Package fs contains an HTTP file system that works with zip contents. +package fs + +import ( + "archive/zip" + "bytes" + "errors" + "fmt" + "io" + "io/ioutil" + "net/http" + "os" + "path" + "sort" + "strings" + "time" +) + +var zipData string + +// file holds unzipped read-only file contents and file metadata. +type file struct { + os.FileInfo + data []byte + fs *statikFS +} + +type statikFS struct { + files map[string]file + dirs map[string][]string +} + +// Register registers zip contents data, later used to initialize +// the statik file system. +func Register(data string) { + zipData = data +} + +// New creates a new file system with the registered zip contents data. +// It unzips all files and stores them in an in-memory map. +func New() (http.FileSystem, error) { + if zipData == "" { + return nil, errors.New("statik/fs: no zip data registered") + } + zipReader, err := zip.NewReader(strings.NewReader(zipData), int64(len(zipData))) + if err != nil { + return nil, err + } + files := make(map[string]file, len(zipReader.File)) + dirs := make(map[string][]string) + fs := &statikFS{files: files, dirs: dirs} + for _, zipFile := range zipReader.File { + fi := zipFile.FileInfo() + f := file{FileInfo: fi, fs: fs} + f.data, err = unzip(zipFile) + if err != nil { + return nil, fmt.Errorf("statik/fs: error unzipping file %q: %s", zipFile.Name, err) + } + files["/"+zipFile.Name] = f + } + for fn := range files { + // go up directories recursively in order to care deep directory + for dn := path.Dir(fn); dn != fn; { + if _, ok := files[dn]; !ok { + files[dn] = file{FileInfo: dirInfo{dn}, fs: fs} + } else { + break + } + fn, dn = dn, path.Dir(dn) + } + } + for fn := range files { + dn := path.Dir(fn) + if fn != dn { + fs.dirs[dn] = append(fs.dirs[dn], path.Base(fn)) + } + } + for _, s := range fs.dirs { + sort.Strings(s) + } + return fs, nil +} + +var _ = os.FileInfo(dirInfo{}) + +type dirInfo struct { + name string +} + +func (di dirInfo) Name() string { return path.Base(di.name) } +func (di dirInfo) Size() int64 { return 0 } +func (di dirInfo) Mode() os.FileMode { return 0755 | os.ModeDir } +func (di dirInfo) ModTime() time.Time { return time.Time{} } +func (di dirInfo) IsDir() bool { return true } +func (di dirInfo) Sys() interface{} { return nil } + +func unzip(zf *zip.File) ([]byte, error) { + rc, err := zf.Open() + if err != nil { + return nil, err + } + defer rc.Close() + return ioutil.ReadAll(rc) +} + +// Open returns a file matching the given file name, or os.ErrNotExists if +// no file matching the given file name is found in the archive. +// If a directory is requested, Open returns the file named "index.html" +// in the requested directory, if that file exists. +func (fs *statikFS) Open(name string) (http.File, error) { + name = strings.Replace(name, "//", "/", -1) + if f, ok := fs.files[name]; ok { + return newHTTPFile(f), nil + } + return nil, os.ErrNotExist +} + +func newHTTPFile(file file) *httpFile { + if file.IsDir() { + return &httpFile{file: file, isDir: true} + } + return &httpFile{file: file, reader: bytes.NewReader(file.data)} +} + +// httpFile represents an HTTP file and acts as a bridge +// between file and http.File. +type httpFile struct { + file + + reader *bytes.Reader + isDir bool + dirIdx int +} + +// Read reads bytes into p, returns the number of read bytes. +func (f *httpFile) Read(p []byte) (n int, err error) { + if f.reader == nil && f.isDir { + return 0, io.EOF + } + return f.reader.Read(p) +} + +// Seek seeks to the offset. +func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) { + return f.reader.Seek(offset, whence) +} + +// Stat stats the file. +func (f *httpFile) Stat() (os.FileInfo, error) { + return f, nil +} + +// IsDir returns true if the file location represents a directory. +func (f *httpFile) IsDir() bool { + return f.isDir +} + +// Readdir returns an empty slice of files, directory +// listing is disabled. +func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) { + var fis []os.FileInfo + if !f.isDir { + return fis, nil + } + di, ok := f.FileInfo.(dirInfo) + if !ok { + return nil, fmt.Errorf("failed to read directory: %q", f.Name()) + } + + // If count is positive, the specified number of files will be returned, + // and if negative, all remaining files will be returned. + // The reading position of which file is returned is held in dirIndex. + fnames := f.file.fs.dirs[di.name] + flen := len(fnames) + + // If dirIdx reaches the end and the count is a positive value, + // an io.EOF error is returned. + // In other cases, no error will be returned even if, for example, + // you specified more counts than the number of remaining files. + start := f.dirIdx + if start >= flen && count > 0 { + return fis, io.EOF + } + var end int + if count < 0 { + end = flen + } else { + end = start + count + } + if end > flen { + end = flen + } + for i := start; i < end; i++ { + fis = append(fis, f.file.fs.files[path.Join(di.name, fnames[i])].FileInfo) + } + f.dirIdx += len(fis) + return fis, nil +} + +func (f *httpFile) Close() error { + return nil +} diff --git a/vendor/github.com/rakyll/statik/fs/walk.go b/vendor/github.com/rakyll/statik/fs/walk.go new file mode 100644 index 00000000..f4eb37d1 --- /dev/null +++ b/vendor/github.com/rakyll/statik/fs/walk.go @@ -0,0 +1,79 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// 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. + +package fs + +import ( + "bytes" + "io" + "net/http" + "path" + "path/filepath" +) + +// Walk walks the file tree rooted at root, +// calling walkFn for each file or directory in the tree, including root. +// All errors that arise visiting files and directories are filtered by walkFn. +// +// As with filepath.Walk, if the walkFn returns filepath.SkipDir, then the directory is skipped. +func Walk(hfs http.FileSystem, root string, walkFn filepath.WalkFunc) error { + dh, err := hfs.Open(root) + if err != nil { + return err + } + di, err := dh.Stat() + if err != nil { + return err + } + fis, err := dh.Readdir(-1) + dh.Close() + if err = walkFn(root, di, err); err != nil { + if err == filepath.SkipDir { + return nil + } + return err + } + for _, fi := range fis { + fn := path.Join(root, fi.Name()) + if fi.IsDir() { + if err = Walk(hfs, fn, walkFn); err != nil { + if err == filepath.SkipDir { + continue + } + return err + } + continue + } + if err = walkFn(fn, fi, nil); err != nil { + if err == filepath.SkipDir { + continue + } + return err + } + } + return nil +} + +// ReadFile reads the contents of the file of hfs specified by name. +// Just as ioutil.ReadFile does. +func ReadFile(hfs http.FileSystem, name string) ([]byte, error) { + fh, err := hfs.Open(name) + if err != nil { + return nil, err + } + var buf bytes.Buffer + _, err = io.Copy(&buf, fh) + fh.Close() + return buf.Bytes(), err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 26512f53..5e3de717 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -239,6 +239,8 @@ github.com/prometheus/tsdb/encoding github.com/prometheus/tsdb/errors github.com/prometheus/tsdb/goversion github.com/prometheus/tsdb/index +# github.com/rakyll/statik v0.1.6 +github.com/rakyll/statik/fs # github.com/samuel/go-zookeeper v0.0.0-20190801204459-3c104360edc8 github.com/samuel/go-zookeeper/zk # go.opencensus.io v0.22.2