Skip to content

Commit 887b4f5

Browse files
env file added
1 parent 1c55301 commit 887b4f5

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

gin-web-app/.env.dev

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
S3_BUCKET=YOURS3BUCKET
2+
SECRET_KEY=YOURSECRETKEYGOESHERE
3+
PORT=3001

gin-web-app/go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/vinodnextcoder/go-web-app
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.21.5
46

57
require (
68
github.com/KyleBanks/depth v1.2.1 // indirect
@@ -20,6 +22,7 @@ require (
2022
github.com/go-playground/universal-translator v0.18.1 // indirect
2123
github.com/go-playground/validator/v10 v10.17.0 // indirect
2224
github.com/goccy/go-json v0.10.2 // indirect
25+
github.com/joho/godotenv v1.5.1 // indirect
2326
github.com/josharian/intern v1.0.0 // indirect
2427
github.com/json-iterator/go v1.1.12 // indirect
2528
github.com/klauspost/cpuid/v2 v2.2.6 // indirect

gin-web-app/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
4242
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
4343
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4444
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
45+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
46+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
4547
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
4648
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
4749
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=

gin-web-app/main.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package main
22

33
import (
4+
"fmt"
5+
"log"
46
"net/http"
7+
"os"
58

9+
"github.com/joho/godotenv"
610
"github.com/gin-gonic/gin"
711
swaggerFiles "github.com/swaggo/files"
812
ginSwagger "github.com/swaggo/gin-swagger"
@@ -24,6 +28,14 @@ import (
2428
// @externalDocs.url https://swagger.io/resources/open-api/
2529
func main() {
2630

31+
err := godotenv.Load(".env.dev")
32+
33+
if err != nil {
34+
log.Fatal("Error loading .env file")
35+
}
36+
37+
port := os.Getenv("PORT")
38+
2739
router := gin.Default()
2840

2941
router.GET("/", helloCall)
@@ -35,7 +47,7 @@ func main() {
3547
router.GET("/userData/:id", getUserByID)
3648
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
3749

38-
router.Run(":3001")
50+
router.Run("0.0.0.0:"+port)
3951
}
4052

4153
type userDetail struct {

0 commit comments

Comments
 (0)