Created
December 5, 2021 06:08
-
-
Save jay-babu/6dd4d6e3b29e2e6d665deeeb6f1b8b54 to your computer and use it in GitHub Desktop.
Golang DI Injectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Provider | |
func NewFirebaseApp() *firebase.App { | |
opt := option.WithCredentialsFile(filename) | |
app, err := firebase.NewApp(context.Background(), nil, opt) | |
if err != nil { | |
log.Fatalf("error initializing app: %v\n", err) | |
} | |
return app | |
} | |
// Provider | |
func NewFirebaseClient(app *firebase.App) *auth.Client { | |
client, err := app.Auth(context.Background()) | |
if err != nil { | |
log.Fatalf("error initializing auth client: %v\n", err) | |
} | |
return client | |
} | |
// Injector | |
func InitializeFirebase() *auth.Client { | |
wire.Build(NewFirebaseApp, NewFirebaseClient) | |
return &auth.Client{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Same Providers as above. | |
func InitializeFirebase() *auth.Client { | |
app := NewFirebaseApp() | |
client := NewFirebaseClient(app) | |
return client | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment