From 3ae859162f8264b42d9207f19fe287fb3afa7111 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Thu, 6 Jun 2019 19:26:00 +0600 Subject: [PATCH] Get rid of init() in config.go --- config.go | 10 +--------- main.go | 12 ++++++++++++ main_test.go | 8 ++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/config.go b/config.go index dff60e87..94b55fd1 100644 --- a/config.go +++ b/config.go @@ -231,9 +231,7 @@ var conf = config{ BufferPoolCalibrationThreshold: 1024, } -func init() { - initSyslog() - +func configure() { keyPath := flag.String("keypath", "", "path of the file with hex-encoded key") saltPath := flag.String("saltpath", "", "path of the file with hex-encoded salt") presetsPath := flag.String("presets", "", "path of the file with presets") @@ -463,10 +461,4 @@ func init() { if conf.BufferPoolCalibrationThreshold < 64 { logFatal("Buffer pool calibration threshold should be greater than or equal to 64") } - - initNewrelic() - initPrometheus() - initDownloading() - initErrorsReporting() - initVips() } diff --git a/main.go b/main.go index 0abeaa82..b3d5d3f0 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,19 @@ const version = "2.2.13" type ctxKey string +func initialize() { + initSyslog() + configure() + initNewrelic() + initPrometheus() + initDownloading() + initErrorsReporting() + initVips() +} + func main() { + initialize() + go func() { var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0 diff --git a/main_test.go b/main_test.go index 8ba34bcc..821007e3 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,9 @@ package main import ( + "os" + "testing" + "github.com/stretchr/testify/suite" ) @@ -10,6 +13,11 @@ type MainTestSuite struct { oldConf config } +func TestMain(m *testing.M) { + initialize() + os.Exit(m.Run()) +} + func (s *MainTestSuite) SetupTest() { s.oldConf = conf }