File tree Expand file tree Collapse file tree 5 files changed +24
-5
lines changed Expand file tree Collapse file tree 5 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 5
5
* .so
6
6
* .dylib
7
7
8
+ .env
9
+
8
10
# Test binary, built with `go test -c`
9
11
* .test
10
12
Original file line number Diff line number Diff line change
1
+ DATABASE_URL = <URL>
2
+ DATABASE_COLLECTION = <COLLECTION>
3
+ DATABASE_NAME = <NAME>
4
+ PORT = <PORT>
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ require (
7
7
github.com/go-stack/stack v1.8.0 // indirect
8
8
github.com/gofiber/fiber/v2 v2.23.0 // indirect
9
9
github.com/golang/snappy v0.0.3 // indirect
10
+ github.com/joho/godotenv v1.4.0 // indirect
10
11
github.com/klauspost/compress v1.13.6 // indirect
11
12
github.com/pkg/errors v0.9.1 // indirect
12
13
github.com/valyala/bytebufferpool v1.0.0 // indirect
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
10
10
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA =
11
11
github.com/golang/snappy v0.0.3 /go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q =
12
12
github.com/google/go-cmp v0.5.2 /go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE =
13
+ github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg =
14
+ github.com/joho/godotenv v1.4.0 /go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4 =
13
15
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s =
14
16
github.com/klauspost/compress v1.13.4 /go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg =
15
17
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc =
Original file line number Diff line number Diff line change 9
9
"github.com/gofiber/fiber/v2"
10
10
"github.com/gofiber/fiber/v2/middleware/cors"
11
11
"github.com/hansmrtn/pay-party-api/models"
12
+ "github.com/joho/godotenv"
12
13
"go.mongodb.org/mongo-driver/bson"
13
14
"go.mongodb.org/mongo-driver/bson/primitive"
14
15
"go.mongodb.org/mongo-driver/mongo"
@@ -20,15 +21,24 @@ type MongoInstance struct {
20
21
DB * mongo.Database
21
22
}
22
23
23
- // Get env variables
24
- var mongoURI = os .Getenv ("DATABASE_URL" )
25
- var dbCollection = os .Getenv ("DATABASE_COLLECTION" )
26
- var dbName = os .Getenv ("DATABASE_NAME" )
27
- var port = os .Getenv ("PORT" )
24
+ var mongoURI string
25
+ var dbCollection string
26
+ var dbName string
27
+ var port string
28
28
29
29
var mg MongoInstance
30
30
31
31
func init () {
32
+ err := godotenv .Load (".env" )
33
+ if err != nil {
34
+ log .Print ("Error loading .env file" )
35
+ }
36
+ // Get env variables
37
+ mongoURI = os .Getenv ("DATABASE_URL" )
38
+ dbCollection = os .Getenv ("DATABASE_COLLECTION" )
39
+ dbName = os .Getenv ("DATABASE_NAME" )
40
+ port = os .Getenv ("PORT" )
41
+
32
42
client , err := mongo .NewClient (options .Client ().ApplyURI (mongoURI ))
33
43
if err != nil {
34
44
log .Fatal (err )
You can’t perform that action at this time.
0 commit comments