| 1 | package mainscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 5 | "log/slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/" |
| 6 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 8 | ) |
| 9 | |
| 10 | // SlogErrorLogger adapts slog.Logger to the interface expected by the prometheus client library for logging errors. |
| 11 | type SlogErrorLoggerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/SlogErrorLogger# struct { |
| 12 | loggerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/SlogErrorLogger#logger. *slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Loggerscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Logger# |
| 13 | } |
| 14 | |
| 15 | func (l *SlogErrorLoggerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/SlogErrorLogger#) Printlnscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/SlogErrorLogger#Println().(v ...any) { |
| 16 | l.loggerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/SlogErrorLogger#logger..Errorscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Logger#Error().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(v...)) |
| 17 | } |
| 18 | |
| 19 | // initSlogger overwrites the global default slog instance |
| 20 | func initSloggerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/initSlogger().(logLevel string, json bool) { |
| 21 | var handler slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Handlerscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Handler# |
| 22 | var level slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Levelscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Level# |
| 23 | switch stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.25.0 strings/ToUpper().(logLevel) { |
| 24 | case "DEBUG": |
| 25 | level = slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.LevelDebugscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/LevelDebug. |
| 26 | case "WARN": |
| 27 | level = slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.LevelWarnscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/LevelWarn. |
| 28 | case "ERROR": |
| 29 | level = slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.LevelErrorscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/LevelError. |
| 30 | default: |
| 31 | level = slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.LevelInfoscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/LevelInfo. |
| 32 | } |
| 33 | if json { |
| 34 | handler = slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.NewJSONHandlerscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/NewJSONHandler().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 os/Stdout., &slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.HandlerOptionsscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/HandlerOptions#{Levelscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/HandlerOptions#Level.: level}) |
| 35 | } else { |
| 36 | handler = slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.NewTextHandlerscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/NewTextHandler().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 os/Stdout., &slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.HandlerOptionsscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/HandlerOptions#{Levelscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/HandlerOptions#Level.: level}) |
| 37 | } |
| 38 | slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.SetDefaultscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/SetDefault().(slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/New().(handler)) |
| 39 | } |
| 40 | |
| 41 | func logFatalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/logFatal().(message string, args ...any) { |
| 42 | slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Error().(message, args...) |
| 43 | osscip-go gomod github.com/golang/go/src go1.25.0 os/.Exitscip-go gomod github.com/golang/go/src go1.25.0 os/Exit().(1) |
| 44 | } |
| 45 | |
| 46 | func logFatalErrorscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/logFatalError().(err error) { |
| 47 | if err != nil { |
| 48 | logFatalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/logFatal().(err.Error()) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // strings |
| 53 | |
| 54 | type caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity# int |
| 55 | |
| 56 | const ( |
| 57 | caseSensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitive. caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity# = 0 |
| 58 | caseInsensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseInsensitive. caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity# = 1 |
| 59 | ) |
| 60 | |
| 61 | func startsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWith().(str, prefix string, cs caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity#) bool { |
| 62 | if cs == caseSensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitive. { |
| 63 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(str, prefix) |
| 64 | } |
| 65 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(str), stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(prefix)) |
| 66 | } |
| 67 | |
| 68 | func startsWithAnyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWithAny().(str string, prefixes []string, cs caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity#) bool { |
| 69 | for _, prefix := range prefixes { |
| 70 | if startsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWith().(str, prefix, cs) { |
| 71 | return true |
| 72 | } |
| 73 | } |
| 74 | return false |
| 75 | } |
| 76 | |
| 77 | func endsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/endsWith().(str, postfix string, cs caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity#) bool { |
| 78 | if cs == caseSensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitive. { |
| 79 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasSuffix().(str, postfix) |
| 80 | } |
| 81 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasSuffix().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(str), stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(postfix)) |
| 82 | } |
| 83 | |
| 84 | func endsWithAnyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/endsWithAny().(str string, postfixes []string, cs caseSensitivityscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitivity#) bool { |
| 85 | for _, postfix := range postfixes { |
| 86 | if endsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/endsWith().(str, postfix, cs) { |
| 87 | return true |
| 88 | } |
| 89 | } |
| 90 | return false |
| 91 | } |
| 92 | |
| 93 | // file |
| 94 | |
| 95 | // Returns if file/dir in path exists. |
| 96 | func fileExistsscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fileExists().(path string) bool { |
| 97 | if len(path) == 0 { |
| 98 | return false |
| 99 | } |
| 100 | if _, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(path); osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 101 | return false |
| 102 | } |
| 103 | return true |
| 104 | } |
| 105 | |
| 106 | // data |
| 107 | |
| 108 | func stringPropertyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/stringProperty().(data map[string]any, key string) (string, error) { |
| 109 | if value, ok := data[key]; ok { |
| 110 | if vStr, ok := value.(string); ok { |
| 111 | return vStr, nil |
| 112 | } else { |
| 113 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("%s is not a string", key) |
| 114 | } |
| 115 | } |
| 116 | return "", nil |
| 117 | } |