prometheus
62 строки · 1.6 Кб
1// Copyright 2018 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14//go:build !builtinassets
15
16package ui
17
18import (
19"net/http"
20"os"
21"path"
22"path/filepath"
23"strings"
24
25"github.com/shurcooL/httpfs/filter"
26"github.com/shurcooL/httpfs/union"
27)
28
29// Assets contains the project's assets.
30var Assets = func() http.FileSystem {
31wd, err := os.Getwd()
32if err != nil {
33panic(err)
34}
35var assetsPrefix string
36switch filepath.Base(wd) {
37case "prometheus":
38// When running Prometheus (without built-in assets) from the repo root.
39assetsPrefix = "./web/ui"
40case "web":
41// When running web tests.
42assetsPrefix = "./ui"
43case "ui":
44// When generating statically compiled-in assets.
45assetsPrefix = "./"
46}
47
48static := filter.Keep(
49http.Dir(path.Join(assetsPrefix, "static")),
50func(path string, fi os.FileInfo) bool {
51return fi.IsDir() ||
52(!strings.HasSuffix(path, "map.js") &&
53!strings.HasSuffix(path, "/bootstrap.js") &&
54!strings.HasSuffix(path, "/bootstrap-theme.css") &&
55!strings.HasSuffix(path, "/bootstrap.css"))
56},
57)
58
59return union.New(map[string]http.FileSystem{
60"/static": static,
61})
62}()
63