From 09235760d2d1306b380e88a4592ea8335be10e82 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 31 Mar 2024 17:46:20 -0700 Subject: [PATCH] Added a config service --- api/services/env.go | 21 +++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ 3 files changed, 24 insertions(+) create mode 100644 api/services/env.go diff --git a/api/services/env.go b/api/services/env.go new file mode 100644 index 0000000..4b39063 --- /dev/null +++ b/api/services/env.go @@ -0,0 +1,21 @@ +package services + +import ( + "go-cook/api/domain" + "log" + "os" + + "github.com/joho/godotenv" +) + +func NewEnvConfig() domain.EnvConfig { + err := godotenv.Load() + if err != nil { + log.Println(err) + } + + return domain.EnvConfig{ + AdminToken: os.Getenv("AdminToken"), + JwtSecret: os.Getenv("JwtSecret"), + } +} diff --git a/go.mod b/go.mod index adbb909..19e3cb0 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/google/uuid v1.5.0 // indirect github.com/huandu/go-sqlbuilder v1.25.0 // indirect github.com/huandu/xstrings v1.3.2 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/labstack/echo-jwt/v4 v4.2.0 // indirect github.com/labstack/echo/v4 v4.11.4 // indirect diff --git a/go.sum b/go.sum index a04d568..e484048 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,8 @@ github.com/huandu/go-sqlbuilder v1.25.0 h1:h1l+6CqeCviPJCnkEZoRGNdfZ5RO9BKMvG3A+ github.com/huandu/go-sqlbuilder v1.25.0/go.mod h1:nUVmMitjOmn/zacMLXT0d3Yd3RHoO2K+vy906JzqxMI= github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=