Skip to content

Commit ec65094

Browse files
authored
Merge pull request #386 from Glimesh/backend-rewrite
Major backend update
2 parents b294d65 + 81ad028 commit ec65094

61 files changed

Lines changed: 6150 additions & 4643 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ################
2+
# SERVER
3+
# ################
4+
5+
# Override default ports 8080 and 443 respectively
6+
HTTP_ADDRESS=0.0.0.0
7+
HTTP_PORT=8080
8+
# HTTP_ENABLE_REDIRECT=TRUE
9+
# HTTPS_PORT=443
10+
# NETWORK_TEST_ON_START=TRUE
11+
12+
# ################
13+
# SSL
14+
# ################
15+
16+
# USE_SSL=TRUE
17+
# SSL_KEY=./certs/key.pem
18+
# SSL_CERT=./certs/cert.pem
19+
20+
# ################
21+
# AUTHORIZATION
22+
# ################
23+
24+
# LOCAL STREAM PROFILE
25+
# STREAM_PROFILE_ACTIVE=TRUE
26+
# STREAM_PROFILE_PATH=./profiles
27+
28+
# WEBHOOK AUTHORIZATION
29+
# WEBHOOK_URL=http://your-server
30+
31+
# ################
32+
# FRONTEND
33+
# ################
34+
35+
FRONTEND_ENABLED=TRUE
36+
FRONTEND_PATH="./web/build"
37+
38+
# ################
39+
# DEBUGGING
40+
# ################
41+
42+
# DEBUG_INCOMING_API_REQUEST=TRUE
43+
# DEBUG_PRINT_ANSWER=TRUE
44+
# DEBUG_PRINT_OFFER=TRUE

.env.development

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
1-
HTTP_ADDRESS=":8080"
2-
ENABLE_HTTP_REDIRECT=
3-
VITE_API_PATH="http://localhost:8080/api"
1+
# ################
2+
# SERVER
3+
# ################
44

5-
# /etc/letsencrypt/live/<your-domain-name>/privkey.pem
6-
SSL_KEY=
5+
# Override default ports 8080 and 443 respectively
6+
HTTP_ADDRESS=0.0.0.0
7+
HTTP_PORT=8080
8+
# HTTP_ENABLE_REDIRECT=TRUE
9+
# HTTPS_PORT=443
10+
# NETWORK_TEST_ON_START=TRUE
711

8-
# /etc/letsencrypt/live/<your-domain-name>/fullchain.pem
9-
SSL_CERT=
12+
# ################
13+
# SSL
14+
# ################
15+
16+
# USE_SSL=TRUE
17+
# SSL_KEY=./certs/key.pem
18+
# SSL_CERT=./certs/cert.pem
19+
20+
# ################
21+
# AUTHORIZATION
22+
# ################
23+
24+
# LOCAL STREAM PROFILE
25+
# STREAM_PROFILE_ACTIVE=TRUE
26+
# STREAM_PROFILE_PATH=./profiles
27+
28+
# WEBHOOK AUTHORIZATION
29+
# WEBHOOK_URL=http://your-server
30+
31+
# ################
32+
# FRONTEND
33+
# ################
34+
35+
FRONTEND_ENABLED=TRUE
36+
FRONTEND_PATH="./web/build"
37+
38+
# ################
39+
# DEBUGGING
40+
# ################
41+
42+
# DEBUG_INCOMING_API_REQUEST=TRUE
43+
# DEBUG_PRINT_ANSWER=TRUE
44+
# DEBUG_PRINT_OFFER=TRUE

.env.production

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
1-
HTTP_ADDRESS=":8080"
2-
ENABLE_HTTP_REDIRECT=
3-
VITE_API_PATH="/api"
1+
# ################
2+
# SERVER
3+
# ################
44

5-
# /etc/letsencrypt/live/<your-domain-name>/privkey.pem
6-
SSL_KEY=
5+
# Override default ports 8080 and 443 respectively
6+
HTTP_ADDRESS=0.0.0.0
7+
HTTP_PORT=8080
8+
# HTTP_ENABLE_REDIRECT=TRUE
9+
# HTTPS_PORT=443
10+
# NETWORK_TEST_ON_START=TRUE
711

8-
# /etc/letsencrypt/live/<your-domain-name>/fullchain.pem
9-
SSL_CERT=
12+
# ################
13+
# SSL
14+
# ################
15+
16+
# USE_SSL=TRUE
17+
# SSL_KEY=./certs/key.pem
18+
# SSL_CERT=./certs/cert.pem
19+
20+
# ################
21+
# AUTHORIZATION
22+
# ################
23+
24+
# LOCAL STREAM PROFILE
25+
# STREAM_PROFILE_ACTIVE=TRUE
26+
# STREAM_PROFILE_PATH=./profiles
27+
28+
# WEBHOOK AUTHORIZATION
29+
# WEBHOOK_URL=http://your-server
30+
31+
# ################
32+
# FRONTEND
33+
# ################
34+
35+
FRONTEND_ENABLED=TRUE
36+
FRONTEND_PATH="./web/build"
37+
38+
# ################
39+
# DEBUGGING
40+
# ################
41+
42+
# DEBUG_INCOMING_API_REQUEST=TRUE
43+
# DEBUG_PRINT_ANSWER=TRUE
44+
# DEBUG_PRINT_OFFER=TRUE

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,12 @@ The frontend can be configured by passing these URL Parameters.
206206
## Environment Variables
207207

208208
The backend can be configured with the following environment variables.
209+
- `STREAM_PROFILE_ACTIVE` - Enables streaming profiles and requires new whep sessions to have a valid token associated with their stream key
210+
- `STREAM_PROFILE_PATH` - The path to store all the profile configurations
209211

210212
- `WEBHOOK_URL` - URL for Webhook Backend. Provides authentication and logging
211-
- `DISABLE_STATUS` - Disable the status API
212-
- `DISABLE_FRONTEND` - Disable the serving of frontend. Only REST APIs + WebRTC is enabled.
213+
- `API_STATUS_DISABLED` - Disable the status API
214+
- `FRONTEND_ENABLED` - Disable the serving of frontend. Only REST APIs + WebRTC is enabled.
213215
- `HTTP_ADDRESS` - HTTP Server Address
214216
- `NETWORK_TEST_ON_START` - When "true" on startup Broadcast Box will check network connectivity
215217

@@ -236,6 +238,7 @@ The backend can be configured with the following environment variables.
236238

237239
- `DEBUG_PRINT_OFFER` - Print WebRTC Offers from client to Broadcast Box. Debug things like accepted codecs.
238240
- `DEBUG_PRINT_ANSWER` - Print WebRTC Answers from Broadcast Box to Browser. Debug things like IP/Ports returned to client.
241+
- `DEBUG_INCOMING_API_REQUEST` - Print API request paths made to the backend
239242

240243
## Authentication and Logging
241244

go.mod

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
module github.com/glimesh/broadcast-box
22

3-
go 1.23.0
4-
5-
toolchain go1.24.0
3+
go 1.24.3
64

75
require (
86
github.com/google/uuid v1.6.0
97
github.com/joho/godotenv v1.5.1
108
github.com/pion/dtls/v3 v3.0.6
11-
github.com/pion/ice/v3 v3.0.16
9+
github.com/pion/ice/v4 v4.0.10
1210
github.com/pion/interceptor v0.1.40
1311
github.com/pion/rtcp v1.2.15
1412
github.com/pion/rtp v1.8.21
15-
github.com/pion/sdp/v3 v3.0.15
1613
github.com/pion/webrtc/v4 v4.1.3
17-
github.com/stretchr/testify v1.10.0
1814
)
1915

2016
require (
2117
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/pmezard/go-difflib v1.0.0 // indirect
19+
gopkg.in/yaml.v3 v3.0.1 // indirect
20+
)
21+
22+
require (
2223
github.com/pion/datachannel v1.5.10 // indirect
23-
github.com/pion/dtls/v2 v2.2.12 // indirect
24-
github.com/pion/ice/v4 v4.0.10 // indirect
2524
github.com/pion/logging v0.2.4 // indirect
2625
github.com/pion/mdns/v2 v2.0.7 // indirect
2726
github.com/pion/randutil v0.1.0 // indirect
2827
github.com/pion/sctp v1.8.39 // indirect
28+
github.com/pion/sdp/v3 v3.0.15
2929
github.com/pion/srtp/v3 v3.0.6 // indirect
30-
github.com/pion/stun/v2 v2.0.0 // indirect
3130
github.com/pion/stun/v3 v3.0.0 // indirect
32-
github.com/pion/transport/v2 v2.2.10 // indirect
3331
github.com/pion/transport/v3 v3.0.7 // indirect
34-
github.com/pion/turn/v3 v3.0.3 // indirect
3532
github.com/pion/turn/v4 v4.0.2 // indirect
36-
github.com/pmezard/go-difflib v1.0.0 // indirect
33+
github.com/stretchr/testify v1.10.0
3734
github.com/wlynxg/anet v0.0.5 // indirect
3835
golang.org/x/crypto v0.39.0 // indirect
3936
golang.org/x/net v0.41.0 // indirect
4037
golang.org/x/sys v0.33.0 // indirect
41-
gopkg.in/yaml.v3 v3.0.1 // indirect
4238
)

go.sum

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
32
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -11,18 +10,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1110
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1211
github.com/pion/datachannel v1.5.10 h1:ly0Q26K1i6ZkGf42W7D4hQYR90pZwzFOjTq5AuCKk4o=
1312
github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oLo8Rs4Py/M=
14-
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
15-
github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk=
16-
github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
1713
github.com/pion/dtls/v3 v3.0.6 h1:7Hkd8WhAJNbRgq9RgdNh1aaWlZlGpYTzdqjy9x9sK2E=
1814
github.com/pion/dtls/v3 v3.0.6/go.mod h1:iJxNQ3Uhn1NZWOMWlLxEEHAN5yX7GyPvvKw04v9bzYU=
19-
github.com/pion/ice/v3 v3.0.16 h1:YoPlNg3jU1UT/DDTa9v/g1vH6A2/pAzehevI1o66H8E=
20-
github.com/pion/ice/v3 v3.0.16/go.mod h1:SdmubtIsCcvdb1ZInrTUz7Iaqi90/rYd1pzbzlMxsZg=
2115
github.com/pion/ice/v4 v4.0.10 h1:P59w1iauC/wPk9PdY8Vjl4fOFL5B+USq1+xbDcN6gT4=
2216
github.com/pion/ice/v4 v4.0.10/go.mod h1:y3M18aPhIxLlcO/4dn9X8LzLLSma84cx6emMSu14FGw=
2317
github.com/pion/interceptor v0.1.40 h1:e0BjnPcGpr2CFQgKhrQisBU7V3GXK6wrfYrGYaU6Jq4=
2418
github.com/pion/interceptor v0.1.40/go.mod h1:Z6kqH7M/FYirg3frjGJ21VLSRJGBXB/KqaTIrdqnOic=
25-
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
2619
github.com/pion/logging v0.2.4 h1:tTew+7cmQ+Mc1pTBLKH2puKsOvhm32dROumOZ655zB8=
2720
github.com/pion/logging v0.2.4/go.mod h1:DffhXTKYdNZU+KtJ5pyQDjvOAh/GsNSyv1lbkFbe3so=
2821
github.com/pion/mdns/v2 v2.0.7 h1:c9kM8ewCgjslaAmicYMFQIde2H9/lrZpjBkN8VwoVtM=
@@ -39,94 +32,28 @@ github.com/pion/sdp/v3 v3.0.15 h1:F0I1zds+K/+37ZrzdADmx2Q44OFDOPRLhPnNTaUX9hk=
3932
github.com/pion/sdp/v3 v3.0.15/go.mod h1:88GMahN5xnScv1hIMTqLdu/cOcUkj6a9ytbncwMCq2E=
4033
github.com/pion/srtp/v3 v3.0.6 h1:E2gyj1f5X10sB/qILUGIkL4C2CqK269Xq167PbGCc/4=
4134
github.com/pion/srtp/v3 v3.0.6/go.mod h1:BxvziG3v/armJHAaJ87euvkhHqWe9I7iiOy50K2QkhY=
42-
github.com/pion/stun/v2 v2.0.0 h1:A5+wXKLAypxQri59+tmQKVs7+l6mMM+3d+eER9ifRU0=
43-
github.com/pion/stun/v2 v2.0.0/go.mod h1:22qRSh08fSEttYUmJZGlriq9+03jtVmXNODgLccj8GQ=
4435
github.com/pion/stun/v3 v3.0.0 h1:4h1gwhWLWuZWOJIJR9s2ferRO+W3zA/b6ijOI6mKzUw=
4536
github.com/pion/stun/v3 v3.0.0/go.mod h1:HvCN8txt8mwi4FBvS3EmDghW6aQJ24T+y+1TKjB5jyU=
46-
github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g=
47-
github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0=
48-
github.com/pion/transport/v2 v2.2.10 h1:ucLBLE8nuxiHfvkFKnkDQRYWYfp8ejf4YBOPfaQpw6Q=
49-
github.com/pion/transport/v2 v2.2.10/go.mod h1:sq1kSLWs+cHW9E+2fJP95QudkzbK7wscs8yYgQToO5E=
50-
github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0=
5137
github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0=
5238
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
53-
github.com/pion/turn/v3 v3.0.3 h1:1e3GVk8gHZLPBA5LqadWYV60lmaKUaHCkm9DX9CkGcE=
54-
github.com/pion/turn/v3 v3.0.3/go.mod h1:vw0Dz420q7VYAF3J4wJKzReLHIo2LGp4ev8nXQexYsc=
5539
github.com/pion/turn/v4 v4.0.2 h1:ZqgQ3+MjP32ug30xAbD6Mn+/K4Sxi3SdNOTFf+7mpps=
5640
github.com/pion/turn/v4 v4.0.2/go.mod h1:pMMKP/ieNAG/fN5cZiN4SDuyKsXtNTr0ccN7IToA1zs=
5741
github.com/pion/webrtc/v4 v4.1.3 h1:YZ67Boj9X/hk190jJZ8+HFGQ6DqSZ/fYP3sLAZv7c3c=
5842
github.com/pion/webrtc/v4 v4.1.3/go.mod h1:rsq+zQ82ryfR9vbb0L1umPJ6Ogq7zm8mcn9fcGnxomM=
5943
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6044
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
61-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
62-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
63-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
64-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
65-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
66-
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
67-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
6845
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
6946
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
70-
github.com/wlynxg/anet v0.0.3/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
7147
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
7248
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
73-
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
74-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
75-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
76-
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
77-
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
78-
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
7949
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
8050
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
81-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
82-
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
83-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
84-
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
85-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
86-
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
87-
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
88-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
89-
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
90-
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
9151
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
9252
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
93-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
94-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
95-
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
96-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
97-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
98-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
99-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
100-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
101-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
102-
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
103-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
104-
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
105-
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
10653
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
10754
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
108-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
109-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
110-
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
111-
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
112-
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
113-
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
114-
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
115-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
116-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
117-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
118-
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
119-
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
120-
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
121-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
122-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
123-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
124-
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
125-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
126-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12755
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12856
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
12957
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
130-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
13158
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
13259
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package environment
2+
3+
import (
4+
"log"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/joho/godotenv"
9+
)
10+
11+
func LoadEnvironmentVariables() {
12+
files := []string{
13+
".env.development",
14+
".env.production",
15+
}
16+
17+
// Load base environment file if available
18+
loadEnvironmentFile(".env")
19+
20+
for _, file := range files {
21+
loadEnvironmentFile(file)
22+
return
23+
}
24+
25+
log.Println("Could not find any environment files")
26+
os.Exit(0)
27+
}
28+
29+
func loadEnvironmentFile(filePath string) {
30+
currentWorkingDirectory, err := os.Getwd()
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
35+
path := filepath.Join(currentWorkingDirectory, filePath)
36+
37+
if _, err := os.Stat(path); err == nil {
38+
err := godotenv.Overload(path)
39+
40+
if err != nil {
41+
log.Println("Error occurred loading environment file", path)
42+
log.Println(err)
43+
44+
os.Exit(0)
45+
}
46+
47+
log.Println("Loaded", filePath)
48+
}
49+
}

0 commit comments

Comments
 (0)