From 2bf888ccfc2d02f0ce9953d80af6044d701e9a2b Mon Sep 17 00:00:00 2001 From: Jacob Greenleaf Date: Thu, 15 Nov 2018 14:00:12 -0800 Subject: [PATCH] Add Fx to main loop --- codegen/template_bundle/template_files.go | 10 +++++++++- codegen/templates/main.tmpl | 8 ++++++++ .../build/services/echo-gateway/main/main.go | 8 ++++++++ .../build/services/example-gateway/main/main.go | 8 ++++++++ glide.lock | 14 +++++++++----- glide.yaml | 4 ++++ 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/codegen/template_bundle/template_files.go b/codegen/template_bundle/template_files.go index ee860401b..adc9d7a24 100644 --- a/codegen/template_bundle/template_files.go +++ b/codegen/template_bundle/template_files.go @@ -1240,6 +1240,7 @@ import ( "syscall" "go.uber.org/zap" + "go.uber.org/fx" "github.com/uber/zanzibar/config" "github.com/uber/zanzibar/runtime" @@ -1307,6 +1308,13 @@ func readFlags() { } func main() { + app := fx.New( + fx.Invoke(zanzibarMain), + ) + app.Run() +} + +func zanzibarMain() { readFlags() server, err := createGateway() if err != nil { @@ -1332,7 +1340,7 @@ func mainTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "main.tmpl", size: 1793, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "main.tmpl", size: 1893, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/codegen/templates/main.tmpl b/codegen/templates/main.tmpl index 0d163c061..1832af976 100644 --- a/codegen/templates/main.tmpl +++ b/codegen/templates/main.tmpl @@ -13,6 +13,7 @@ import ( "syscall" "go.uber.org/zap" + "go.uber.org/fx" "github.com/uber/zanzibar/config" "github.com/uber/zanzibar/runtime" @@ -80,6 +81,13 @@ func readFlags() { } func main() { + app := fx.New( + fx.Invoke(zanzibarMain), + ) + app.Run() +} + +func zanzibarMain() { readFlags() server, err := createGateway() if err != nil { diff --git a/examples/example-gateway/build/services/echo-gateway/main/main.go b/examples/example-gateway/build/services/echo-gateway/main/main.go index e54957296..f897e6876 100644 --- a/examples/example-gateway/build/services/echo-gateway/main/main.go +++ b/examples/example-gateway/build/services/echo-gateway/main/main.go @@ -31,6 +31,7 @@ import ( "strings" "syscall" + "go.uber.org/fx" "go.uber.org/zap" "github.com/uber/zanzibar/config" @@ -98,6 +99,13 @@ func readFlags() { } func main() { + app := fx.New( + fx.Invoke(zanzibarMain), + ) + app.Run() +} + +func zanzibarMain() { readFlags() server, err := createGateway() if err != nil { diff --git a/examples/example-gateway/build/services/example-gateway/main/main.go b/examples/example-gateway/build/services/example-gateway/main/main.go index e653f8a7a..aa835f227 100644 --- a/examples/example-gateway/build/services/example-gateway/main/main.go +++ b/examples/example-gateway/build/services/example-gateway/main/main.go @@ -31,6 +31,7 @@ import ( "strings" "syscall" + "go.uber.org/fx" "go.uber.org/zap" "github.com/uber/zanzibar/config" @@ -98,6 +99,13 @@ func readFlags() { } func main() { + app := fx.New( + fx.Invoke(zanzibarMain), + ) + app.Run() +} + +func zanzibarMain() { readFlags() server, err := createGateway() if err != nil { diff --git a/glide.lock b/glide.lock index 9492ceff4..f4dd03777 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: d22933e0e067cdcc884b19097c2ac35cebe7c4657722bb8f9c8363b71755cd76 -updated: 2018-11-06T16:13:52.454011-08:00 +hash: 5bc390ca2677f02ccd0e07e337e2e0b4be3ca21d3f2d60cf4f4d5967ff666c3c +updated: 2018-11-15T13:55:27.615724786-08:00 imports: - name: github.com/anmitsu/go-shlex version: 648efa622239a2f6ff949fed78ee37b48d499ba4 @@ -29,7 +29,7 @@ imports: - name: github.com/google/uuid version: 16ca3eab7d2086fd5a82993a291cbf3b87fe38b7 - name: github.com/jessevdk/go-flags - version: 5de817a9aa209ed35a164cb04aec82b7df1a47a6 + version: 1c38ed7ad0cc3d9e66649ac398c30e45f395c4eb - name: github.com/julienschmidt/httprouter version: 26a05976f9bf5c3aa992cc20e8588c359418ee58 - name: github.com/kardianos/osext @@ -113,6 +113,10 @@ imports: version: 3f523f4c14b6e925da10475eb0447c2f28614aac - name: go.uber.org/atomic version: 1ea20fb1cbb1cc08cbd0d913a96dead89aa18289 +- name: go.uber.org/dig + version: 12c8adaa5e6a24ad02198588082d95582ee16e5b +- name: go.uber.org/fx + version: 9c82e1daccdcbd27387a1f044bd3dc6d3f878bf4 - name: go.uber.org/multierr version: 3c4937480c32f4c13a875a1829af76c98ca3d40a - name: go.uber.org/thriftrw @@ -150,11 +154,11 @@ imports: - zapcore - zaptest/observer - name: golang.org/x/net - version: e11730110bbd884bbf19550bfafe9d69519ce29e + version: adae6a3d119ae4890b46832a2e88a95adc62b8e7 subpackages: - context - name: golang.org/x/tools - version: 45ff765b4815d34d8b80220fd05c79063b185ce1 + version: f87c222f148786695d2ee5761b06751bb9211f61 subpackages: - cmd/goimports - name: gopkg.in/validator.v2 diff --git a/glide.yaml b/glide.yaml index 91e8215a3..160c705bf 100644 --- a/glide.yaml +++ b/glide.yaml @@ -67,3 +67,7 @@ import: version: master - package: gopkg.in/validator.v2 version: master +- package: go.uber.org/fx + +# Transitive dependency of fx +- package: go.uber.org/dig