Skip to content

Commit f58d0e0

Browse files
committed
Optionally read a .env file for env vars.
Signed-off-by: Katharine Berry <[email protected]>
1 parent b83d6e8 commit f58d0e0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

service/assistant/config/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
package config
1616

17-
import "os"
17+
import (
18+
"log"
19+
"os"
20+
21+
"github.com/joho/godotenv"
22+
)
1823

1924
// TODO: something reasonable.
2025

@@ -35,6 +40,14 @@ func GetConfig() *Config {
3540
}
3641

3742
func init() {
43+
// Load .env file if it exists
44+
if err := godotenv.Load(); err != nil {
45+
// Only log if the file exists but couldn't be loaded
46+
if !os.IsNotExist(err) {
47+
log.Printf("Error loading .env file: %v", err)
48+
}
49+
}
50+
3851
c = Config{
3952
GeminiKey: os.Getenv("GEMINI_KEY"),
4053
MapboxKey: os.Getenv("MAPBOX_KEY"),

service/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.23.3
77
require (
88
github.com/google/uuid v1.6.0
99
github.com/honeycombio/beeline-go v1.18.0
10+
github.com/joho/godotenv v1.5.1
1011
github.com/redis/go-redis/v9 v9.7.1
1112
github.com/yuin/gopher-lua v1.1.1
1213
golang.org/x/exp v0.0.0-20250228200357-dead58393ab7

service/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ github.com/honeycombio/beeline-go v1.18.0 h1:usCoLWAX0kMHPOd9+4sVM8MH0FZTTKaBm3U
3838
github.com/honeycombio/beeline-go v1.18.0/go.mod h1:EQ+Wz76mVNAT98hwahTqna61y/XVVxEqWyh4k87BXSM=
3939
github.com/honeycombio/libhoney-go v1.25.0 h1:r33tlX90HtafK0bgRcjfNnsrJ9ZMTKuI/1DYaOFCc1o=
4040
github.com/honeycombio/libhoney-go v1.25.0/go.mod h1:Fc0HjqlwYf5xy6H34EItpOverAGbCixnYOX3YTUQovg=
41+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
42+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
4143
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
4244
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
4345
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)