firebase / firebase/firebase-admin-go
FIREBASE_DATABASE_EMULATOR_HOST environment variable with IP address errors and exits application
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 274
- Avg merge
- 10h 39m
- Merged PRs (30d)
- 2
Description
### [REQUIRED] Step 2: Describe your environment
* Operating System version: Windows 11 Pro
* Firebase SDK version: firebase.google.com/go/v4
* Library version: _____
* Firebase Product: database
### [REQUIRED] Step 3: Describe the problem
Setting the FIREBASE_DATABASE_EMULATOR_HOST environment variable with an IP address errors and exit's the application.
#### Steps to reproduce:
Create an application using the firebase sdk for golang
Load FIREBASE_DATABASE_EMULATOR_HOST={IP_ADDRESS} into your environment
The application should crash

#### Relevant Code:
```go
package firebase
import (
"context"
"log"
"os"
fb "firebase.google.com/go/v4"
"google.golang.org/api/option"
)
func Firebase(ctx context.Context) *fb.App {
db := os.Getenv("DATABASE_URL")
if db == "" {
log.Fatal("Error loading DATABASE_URL from .env file")
}
pid := os.Getenv("PROJECT_ID")
if pid == "" {
log.Fatal("Error loading PROJECT_ID from .env file")
}
config := &fb.Config{
DatabaseURL: db,
ProjectID: pid,
}
env := os.Getenv("APP_ENV")
var opt option.ClientOption
if env == "development" {
cred := os.Getenv("FIREBASE_CONFIG")
if cred == "" {
log.Fatal("Error loading FIREBASE_CONFIG from .env file")
}
opt = option.WithCredentialsFile(cred)
}
if value := os.Getenv("FIRESTORE_EMULATOR_HOST"); value != "" {
log.Printf("Using Firestore Emulator: %s", value)
app, err := fb.NewApp(ctx, config, opt)
if err != nil {
log.Fatalln(err)
}
return app
} else {
app, err := fb.NewApp(ctx, config)
if err != nil {
log.Fatalln(err)
}
return app
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.