Skip to content

Commit e58c424

Browse files
committed
feat: add env file to question-service
1 parent a38eaca commit e58c424

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

apps/question-service/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json
33
test_create_api_results.txt
44
test_list_api_results.txt
55
test_update_api_results.txt
6+
.env

apps/question-service/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require (
1010
google.golang.org/grpc v1.67.0
1111
)
1212

13+
require github.com/joho/godotenv v1.5.1
14+
1315
require (
1416
cloud.google.com/go v0.115.1 // indirect
1517
cloud.google.com/go/auth v0.9.4 // indirect

apps/question-service/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gT
8181
github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA=
8282
github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDPT0hH1s=
8383
github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A=
84+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
85+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
8486
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8587
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8688
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=

apps/question-service/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/go-chi/chi/v5"
1515
"github.com/go-chi/chi/v5/middleware"
1616
"github.com/go-chi/cors"
17+
"github.com/joho/godotenv"
1718
"google.golang.org/api/option"
1819
)
1920

@@ -33,9 +34,16 @@ func initFirestore(ctx context.Context, credentialsPath string) (*firestore.Clie
3334
}
3435

3536
func main() {
37+
// Load .env file
38+
err := godotenv.Load()
39+
if err != nil {
40+
log.Fatal("Error loading .env file")
41+
}
42+
3643
// Initialize Firestore client
3744
ctx := context.Background()
38-
client, err := initFirestore(ctx, "cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json")
45+
firebaseCredentialPath := os.Getenv("FIREBASE_CREDENTIAL_PATH")
46+
client, err := initFirestore(ctx, firebaseCredentialPath)
3947
if err != nil {
4048
log.Fatalf("Failed to initialize Firestore client: %v", err)
4149
}

0 commit comments

Comments
 (0)