Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose DepsTree through the main fx module #821

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions codegen/templates/main.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Result struct {
Gateway *zanzibar.Gateway
// Provider is an abstraction over the Zanzibar config store
Provider uberconfig.Provider `name:"zanzibarConfig"`
// Deps is a reference to the dependency tree inside zanzibar gateway
Deps *service.DependenciesTree
}

func main() {
Expand All @@ -74,7 +76,7 @@ func run(gateway *zanzibar.Gateway) {
// or modify Result. Most users should use Module instead.
func New(p Params) (Result, error) {
readFlags()
gateway, err := createGateway()
gateway, deps, err := createGateway()
if err != nil {
return Result{}, errors.Wrap(err, "failed to create gateway server")
}
Expand Down Expand Up @@ -113,16 +115,17 @@ func New(p Params) (Result, error) {
return Result{
Gateway: gateway,
Provider: provider,
Deps: deps,
}, nil
}

func createGateway() (*zanzibar.Gateway, error) {
func createGateway() (*zanzibar.Gateway, *service.DependenciesTree, error) {
cfg := getConfig()
gateway, _, err := service.CreateGateway(cfg, app.AppOptions)
gateway, deps, err := service.CreateGateway(cfg, app.AppOptions)
if err != nil {
return nil, err
return nil, nil, err
}
return gateway, nil
return gateway, deps.(*service.DependenciesTree), nil
}

func getConfig() *zanzibar.StaticConfig {
Expand Down
6 changes: 4 additions & 2 deletions codegen/templates/main_test.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
"syscall"
"testing"

"github.com/stretchr/testify/assert"
zanzibar "github.com/uber/zanzibar/runtime"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
zanzibar "github.com/uber/zanzibar/runtime"

module "{{$instance.PackageInfo.ModulePackagePath}}"
)
Expand Down Expand Up @@ -57,14 +58,15 @@ func TestStartGateway(t *testing.T) {
),
)

gateway, err := createGateway()
gateway, deps, err := createGateway()
if err != nil {
testLogger.Error(
"Failed to CreateGateway in TestStartGateway()",
zap.Error(err),
)
return
}
assert.NotNil(t, deps)

cachedServer = gateway
err = gateway.Bootstrap()
Expand Down