Refactor CLI out of main.go into app module#208
Conversation
| type proxyRunner interface { | ||
| Start() error | ||
| Stop() | ||
| } |
There was a problem hiding this comment.
I wasn't a fan of the: func interruptCh() <-chan interface{} {
I've opted for a lifecycle interface + context prop in an attempt to be more graceful and idiomatic.
| type CLI struct { | ||
| name string | ||
| version string | ||
| extraOpts []fx.Option |
There was a problem hiding this comment.
supports DI configuration if needed.
|
|
||
| const ( | ||
| DefaultName = "s2s-proxy" | ||
| DefaultVersion = "0.0.1" // TODO: configure build-time injection of version. |
There was a problem hiding this comment.
will follow-up this PR with proper release tagging & version gha improvements.
| func main() { | ||
| if err := run(os.Args); err != nil { | ||
| ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) | ||
| defer stop() | ||
|
|
||
| // TODO: configure build-time injection of version. | ||
| if err := cli.New(cli.DefaultName, cli.DefaultVersion).Run(ctx, os.Args); err != nil { | ||
| panic(err) | ||
| } | ||
| } |
There was a problem hiding this comment.
simplified main.go!
cmd/proxy/main.go
Outdated
| defer stop() | ||
|
|
||
| // TODO: configure build-time injection of version. | ||
| if err := cli.New(cli.DefaultName, cli.DefaultVersion).Run(ctx, os.Args); err != nil { |
There was a problem hiding this comment.
would app be a better module name instead of cli because this package is doing more than argument parsing. It wires the app, builds the Fx graph, etc.
cli/cli.go
Outdated
| Stop() | ||
| } | ||
|
|
||
| type CLI struct { |
There was a problem hiding this comment.
probably name it as App to for the same reason of renaming the module to app.
9b55879 to
91776ee
Compare
What was changed
Refactors cli out of
main.gointo its own module - and adds tests.Why?
Configurability & testability.