mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Simplify cli
This commit is contained in:
+2
-27
@@ -18,10 +18,6 @@ import (
|
|||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
base
|
base
|
||||||
|
|
||||||
prometheusListener net.Listener
|
|
||||||
prometheus *stats.PrometheusFactory
|
|
||||||
statsdFactory *stats.StatsdFactory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Proxy) Run(cli *CLI, version string) error {
|
func (c *Proxy) Run(cli *CLI, version string) error {
|
||||||
@@ -32,7 +28,7 @@ func (c *Proxy) Run(cli *CLI, version string) error {
|
|||||||
return c.Execute()
|
return c.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Proxy) Execute() error { // nolint: funlen
|
func (c *Proxy) Execute() error {
|
||||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
|
||||||
zerolog.TimestampFieldName = "timestamp"
|
zerolog.TimestampFieldName = "timestamp"
|
||||||
zerolog.LevelFieldName = "level"
|
zerolog.LevelFieldName = "level"
|
||||||
@@ -59,10 +55,6 @@ func (c *Proxy) Execute() error { // nolint: funlen
|
|||||||
PreferIP: c.Config.PreferIP.Value(mtglib.DefaultPreferIP),
|
PreferIP: c.Config.PreferIP.Value(mtglib.DefaultPreferIP),
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Concurrency == 0 {
|
|
||||||
opts.Concurrency = mtglib.DefaultConcurrency
|
|
||||||
}
|
|
||||||
|
|
||||||
opts.Logger.BindStr("configuration", c.Config.String()).Debug("configuration")
|
opts.Logger.BindStr("configuration", c.Config.String()).Debug("configuration")
|
||||||
|
|
||||||
c.setupAntiReplayCache(&opts)
|
c.setupAntiReplayCache(&opts)
|
||||||
@@ -89,20 +81,8 @@ func (c *Proxy) Execute() error { // nolint: funlen
|
|||||||
go proxy.Serve(listener) // nolint: errcheck
|
go proxy.Serve(listener) // nolint: errcheck
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|
||||||
listener.Close()
|
listener.Close()
|
||||||
|
proxy.Shutdown()
|
||||||
if c.prometheusListener != nil {
|
|
||||||
c.prometheusListener.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.prometheus != nil {
|
|
||||||
c.prometheus.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.statsdFactory != nil {
|
|
||||||
c.statsdFactory.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -173,8 +153,6 @@ func (c *Proxy) setupEventStream(opts *mtglib.ProxyOpts) error {
|
|||||||
return fmt.Errorf("cannot build statsd observer: %w", err)
|
return fmt.Errorf("cannot build statsd observer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.statsdFactory = &statsdFactory
|
|
||||||
|
|
||||||
factories = append(factories, statsdFactory.Make)
|
factories = append(factories, statsdFactory.Make)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,9 +169,6 @@ func (c *Proxy) setupEventStream(opts *mtglib.ProxyOpts) error {
|
|||||||
|
|
||||||
go prometheus.Serve(listener) // nolint: errcheck
|
go prometheus.Serve(listener) // nolint: errcheck
|
||||||
|
|
||||||
c.prometheusListener = listener
|
|
||||||
c.prometheus = prometheus
|
|
||||||
|
|
||||||
factories = append(factories, prometheus.Make)
|
factories = append(factories, prometheus.Make)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user