Skip to content

Instantly share code, notes, and snippets.

@jay-babu
Created December 5, 2021 06:08
Show Gist options
  • Save jay-babu/6dd4d6e3b29e2e6d665deeeb6f1b8b54 to your computer and use it in GitHub Desktop.
Save jay-babu/6dd4d6e3b29e2e6d665deeeb6f1b8b54 to your computer and use it in GitHub Desktop.
Golang DI Injectors
// 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{}
}
// 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