/
def.go
42 lines (33 loc) · 1012 Bytes
/
def.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Package def provides default values for both commands and tests.
package def
import (
"fmt"
"net/http"
"time"
"github.com/jmoiron/sqlx"
"github.com/powerman/getenv"
"github.com/powerman/must"
"github.com/powerman/sensitive"
"github.com/powerman/sqlxx"
"github.com/prometheus/client_golang/prometheus"
)
func init() { //nolint:gochecknoinits // Ensure time.Now() assigned to global vars uses UTC.
// Make time.Now()==time.Now().UTC() https://github.com/golang/go/issues/19486
time.Local = nil
}
// Init must be called once before using this package.
// It provides common initialization for both commands and tests.
func Init() error {
// Make sure no one occasionally uses global objects.
http.DefaultServeMux = nil
prometheus.DefaultRegisterer = nil
prometheus.DefaultGatherer = nil
must.AbortIf = must.PanicIf
sqlx.NameMapper = sqlxx.ToSnake
sensitive.Redact()
setupLog()
if hostnameErr != nil {
return fmt.Errorf("os.Hostname: %w", hostnameErr)
}
return getenv.LastErr()
}