Go Get Env not finding .env after deployment

triptoafsin
HOBBY

6 months ago

I've made REST api with GO, I've used gogetenv to load the .env file, but it doesn't find it in the Railway environment and the app crashes

Solved

4 Replies

6 months ago

You shouldn't have .env files in production, if you want to load environment variables then you can do so in the service's Variables tab. I don't have experience with Go but you'll need to make gogetenv fail gracefully if it doesn't find a .env file


triptoafsin
HOBBY

6 months ago

Thanks I solved the issue, it was quite unique how Go handles these scenarios


dev

You shouldn't have .env files in production, if you want to load environment variables then you can do so in the service's Variables tab. I don't have experience with Go but you'll need to make gogetenv fail gracefully if it doesn't find a .env file

triptoafsin
HOBBY

6 months ago

Thanks I solved the issue, it was quite unique how Go handles these scenarios

I just had to prevent the panic/fail and fallback to system default to make it work


6 months ago

Awesome, I'm very glad you got it working


Status changed to Solved dev 6 months ago


Go Get Env not finding .env after deployment - Railway Help Station