1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-08-08 04:42:07 +03:00

Refactor repository layout and convert build system to Mage.

This commit implements a massive refactor of the repository, and
moves the build system over to use Mage (magefile.org) which should
allow seamless building across multiple platforms.
This commit is contained in:
Will Rouesnel
2018-02-23 01:55:49 +11:00
parent 3e6cf08dc5
commit 989489096e
269 changed files with 35309 additions and 2017 deletions

View File

@@ -2,6 +2,8 @@ package main
import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"text/template"
"time"
@@ -38,6 +40,7 @@ type Config struct { // nolint: maligned
Vendor bool
Cyclo int
LineLength int
MisspellLocale string
MinConfidence float64
MinOccurrences int
MinConstLength int
@@ -128,6 +131,7 @@ var config = &Config{
Concurrency: runtime.NumCPU(),
Cyclo: 10,
LineLength: 80,
MisspellLocale: "",
MinConfidence: 0.8,
MinOccurrences: 3,
MinConstLength: 3,
@@ -135,3 +139,54 @@ var config = &Config{
Sort: []string{"none"},
Deadline: jsonDuration(time.Second * 30),
}
func loadConfigFile(filename string) error {
r, err := os.Open(filename)
if err != nil {
return err
}
defer r.Close() // nolint: errcheck
err = json.NewDecoder(r).Decode(config)
if err != nil {
return err
}
for _, disable := range config.Disable {
for i, enable := range config.Enable {
if enable == disable {
config.Enable = append(config.Enable[:i], config.Enable[i+1:]...)
break
}
}
}
return err
}
func findDefaultConfigFile() (fullPath string, found bool, err error) {
prevPath := ""
dirPath, err := os.Getwd()
if err != nil {
return "", false, err
}
for dirPath != prevPath {
fullPath, found, err = findConfigFileInDir(dirPath)
if err != nil || found {
return fullPath, found, err
}
prevPath, dirPath = dirPath, filepath.Dir(dirPath)
}
return "", false, nil
}
func findConfigFileInDir(dirPath string) (fullPath string, found bool, err error) {
fullPath = filepath.Join(dirPath, defaultConfigPath)
if _, err := os.Stat(fullPath); err != nil {
if os.IsNotExist(err) {
return "", false, nil
}
return "", false, err
}
return fullPath, true, nil
}