diff --git a/cmd/litestream/main.go b/cmd/litestream/main.go index 9698bf50..74068e16 100644 --- a/cmd/litestream/main.go +++ b/cmd/litestream/main.go @@ -23,6 +23,7 @@ import ( "github.com/benbjohnson/litestream/gcs" "github.com/benbjohnson/litestream/s3" "github.com/benbjohnson/litestream/sftp" + "github.com/joho/godotenv" _ "github.com/mattn/go-sqlite3" "gopkg.in/yaml.v2" ) @@ -55,6 +56,14 @@ func NewMain() *Main { // Run executes the program. func (m *Main) Run(ctx context.Context, args []string) (err error) { + // Load environment variables from .env file + if _, err := os.Stat(".env"); err == nil { + err = godotenv.Load(".env") + if err != nil { + return fmt.Errorf("error loading .env file: %w", err) + } + } + // Execute replication command if running as a Windows service. if isService, err := isWindowsService(); err != nil { return err diff --git a/go.mod b/go.mod index 3eb918c9..91752d28 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/kr/fs v0.1.0 // indirect github.com/mattn/go-ieproxy v0.0.11 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect diff --git a/go.sum b/go.sum index ee4a4621..1aeb2f03 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=