From 698fb76b98c46c677abe13fdc93afc6c4f38c39e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 14 Oct 2021 20:55:35 +0300 Subject: refactor --- cmd/dtailhealth/main.go | 49 ++++++++++++++++++++++++++++++++++++++++++++ cmd/dtailhealthcheck/main.go | 49 -------------------------------------------- 2 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 cmd/dtailhealth/main.go delete mode 100644 cmd/dtailhealthcheck/main.go (limited to 'cmd') diff --git a/cmd/dtailhealth/main.go b/cmd/dtailhealth/main.go new file mode 100644 index 0000000..7e54b1c --- /dev/null +++ b/cmd/dtailhealth/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "context" + "flag" + "fmt" + "os" + "sync" + + "net/http" + _ "net/http" + _ "net/http/pprof" + + "github.com/mimecast/dtail/internal/clients" + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/io/dlog" + "github.com/mimecast/dtail/internal/io/signal" + "github.com/mimecast/dtail/internal/source" +) + +// The evil begins here. +func main() { + var args config.Args + var pprof int + + flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port") + flag.StringVar(&args.Logger, "logger", config.DefaultHealthCheckLogger, "Logger name") + flag.StringVar(&args.LogLevel, "logLevel", "none", "Log level") + flag.StringVar(&args.ServersStr, "server", "", "Remote server to connect") + flag.Parse() + + config.Setup(source.HealthCheck, &args, flag.Args()) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + var wg sync.WaitGroup + wg.Add(1) + dlog.Start(ctx, &wg, source.HealthCheck) + + if pprof > -1 { + // For debugging purposes only + pprofArgs := fmt.Sprintf("0.0.0.0:%d", pprof) + go http.ListenAndServe(pprofArgs, nil) + dlog.Client.Info("Started PProf", pprofArgs) + } + + healthClient, _ := clients.NewHealthClient(args) + os.Exit(healthClient.Start(ctx, signal.NoCh(ctx))) +} diff --git a/cmd/dtailhealthcheck/main.go b/cmd/dtailhealthcheck/main.go deleted file mode 100644 index 7e54b1c..0000000 --- a/cmd/dtailhealthcheck/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "os" - "sync" - - "net/http" - _ "net/http" - _ "net/http/pprof" - - "github.com/mimecast/dtail/internal/clients" - "github.com/mimecast/dtail/internal/config" - "github.com/mimecast/dtail/internal/io/dlog" - "github.com/mimecast/dtail/internal/io/signal" - "github.com/mimecast/dtail/internal/source" -) - -// The evil begins here. -func main() { - var args config.Args - var pprof int - - flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port") - flag.StringVar(&args.Logger, "logger", config.DefaultHealthCheckLogger, "Logger name") - flag.StringVar(&args.LogLevel, "logLevel", "none", "Log level") - flag.StringVar(&args.ServersStr, "server", "", "Remote server to connect") - flag.Parse() - - config.Setup(source.HealthCheck, &args, flag.Args()) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - var wg sync.WaitGroup - wg.Add(1) - dlog.Start(ctx, &wg, source.HealthCheck) - - if pprof > -1 { - // For debugging purposes only - pprofArgs := fmt.Sprintf("0.0.0.0:%d", pprof) - go http.ListenAndServe(pprofArgs, nil) - dlog.Client.Info("Started PProf", pprofArgs) - } - - healthClient, _ := clients.NewHealthClient(args) - os.Exit(healthClient.Start(ctx, signal.NoCh(ctx))) -} -- cgit v1.2.3