prometheus

Форк
0
/
generate.go 
99 строк · 2.3 Кб
1
// Copyright 2022 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 plugins
15

16
package main
17

18
import (
19
	"fmt"
20
	"log"
21
	"os"
22
	"path"
23
	"path/filepath"
24

25
	"gopkg.in/yaml.v2"
26
)
27

28
//go:generate go run generate.go
29

30
func main() {
31
	data, err := os.ReadFile(filepath.Join("..", "plugins.yml"))
32
	if err != nil {
33
		log.Fatal(err)
34
	}
35

36
	var plugins []string
37
	err = yaml.Unmarshal(data, &plugins)
38
	if err != nil {
39
		log.Fatal(err)
40
	}
41

42
	f, err := os.Create("plugins.go")
43
	if err != nil {
44
		log.Fatal(err)
45
	}
46
	defer f.Close()
47
	_, err = f.WriteString(`// Copyright 2022 The Prometheus Authors
48
// Licensed under the Apache License, Version 2.0 (the "License");
49
// you may not use this file except in compliance with the License.
50
// You may obtain a copy of the License at
51
//
52
// http://www.apache.org/licenses/LICENSE-2.0
53
//
54
// Unless required by applicable law or agreed to in writing, software
55
// distributed under the License is distributed on an "AS IS" BASIS,
56
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57
// See the License for the specific language governing permissions and
58
// limitations under the License.
59

60
// This file is generated by "make plugins".
61

62
package plugins
63

64
`)
65
	if err != nil {
66
		log.Fatal(err)
67
	}
68

69
	if len(plugins) == 0 {
70
		return
71
	}
72

73
	_, err = f.WriteString("import (\n")
74
	if err != nil {
75
		log.Fatal(err)
76
	}
77

78
	for i, plugin := range plugins {
79
		_, err = f.WriteString(fmt.Sprintf("\t// Register %s plugin.\n", path.Base(plugin)))
80
		if err != nil {
81
			log.Fatal(err)
82
		}
83
		_, err = f.WriteString(fmt.Sprintf("\t_ \"%s\"\n", plugin))
84
		if err != nil {
85
			log.Fatal(err)
86
		}
87
		if i < len(plugins)-1 {
88
			_, err = f.WriteString("\n")
89
			if err != nil {
90
				log.Fatal(err)
91
			}
92
		}
93
	}
94

95
	_, err = f.WriteString(")\n")
96
	if err != nil {
97
		log.Fatal(err)
98
	}
99
}
100

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

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

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

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