Skip to content

Commit

Permalink
Merge pull request #38 from mtlynch/env-example
Browse files Browse the repository at this point in the history
Rename .env to .env.example
  • Loading branch information
0x2E authored Dec 24, 2024
2 parents 472a41d + c8bdbf9 commit 436f6a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .env → .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# To populate a .env file, copy this file to .env:
#
# cp -n .env.example .env

# Web Server
HOST="0.0.0.0"
PORT=8080
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
tmp/
build/
dist/

# The .env file may contain secrets, so exclude it from source control.
.env*
# .env.example is an exception as it only contains dummy secrets.
!.env.example
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Fusion can be configured in many ways:
- Create a `.env` file in the same directory as the binary file, and then copy the items you want to modify into it.
- NOTE: values in `.env` file can be overwritten by system environment variables.

All configuration items can be found [here](https://github.com/0x2E/fusion/blob/main/.env).
All configuration items can be found [here](https://github.com/0x2E/fusion/blob/main/.env.example).

## Credits

Expand Down
13 changes: 10 additions & 3 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package conf
import (
"errors"
"fmt"
"log"
"os"

"github.com/caarlos0/env/v11"
"github.com/joho/godotenv"
)

const Debug = false
const (
Debug = false

dotEnvFilename = ".env"
)

var Conf struct {
Host string `env:"HOST" envDefault:"0.0.0.0"`
Expand All @@ -23,11 +28,13 @@ var Conf struct {
}

func Load() {
if err := godotenv.Load(".env"); err != nil {
if err := godotenv.Load(dotEnvFilename); err != nil {
if !os.IsNotExist(err) {
panic(err)
}
fmt.Println("cannot find .env, skip")
log.Printf("no configuration file found at %s", dotEnvFilename)
} else {
log.Printf("read configuration from %s", dotEnvFilename)
}
if err := env.Parse(&Conf); err != nil {
panic(err)
Expand Down

0 comments on commit 436f6a8

Please sign in to comment.