prometheus

Форк
0
/
ui.go 
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

16
package ui
17

18
import (
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.
30
var Assets = func() http.FileSystem {
31
	wd, err := os.Getwd()
32
	if err != nil {
33
		panic(err)
34
	}
35
	var assetsPrefix string
36
	switch filepath.Base(wd) {
37
	case "prometheus":
38
		// When running Prometheus (without built-in assets) from the repo root.
39
		assetsPrefix = "./web/ui"
40
	case "web":
41
		// When running web tests.
42
		assetsPrefix = "./ui"
43
	case "ui":
44
		// When generating statically compiled-in assets.
45
		assetsPrefix = "./"
46
	}
47

48
	static := filter.Keep(
49
		http.Dir(path.Join(assetsPrefix, "static")),
50
		func(path string, fi os.FileInfo) bool {
51
			return 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

59
	return union.New(map[string]http.FileSystem{
60
		"/static": static,
61
	})
62
}()
63

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.