diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..b08736cdf --- /dev/null +++ b/.env.example @@ -0,0 +1,36 @@ +# Installation +INSTALL_PORT=80 +AUTO_INSTALL=false + +# Database +DB_TYPE= +DB_USERNAME= +DB_PASSWORD= +DB_HOST= +DB_NAME= +DB_FILE= + +# Site +LANGUAGE=en-US +SITE_NAME=Apache Answer +SITE_URL= +CONTACT_EMAIL= + +# Admin +ADMIN_NAME= +ADMIN_PASSWORD= +ADMIN_EMAIL= + +# Content +EXTERNAL_CONTENT_DISPLAY=ask_before_display + +# Swagger +SWAGGER_HOST= +SWAGGER_ADDRESS_PORT= + +# Server +SITE_ADDR=0.0.0.0:3000 + +# Logging +LOG_LEVEL=INFO +LOG_PATH= diff --git a/.gitignore b/.gitignore index 257ef31d6..ba66f51a0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ dist/ # Lint setup generated file .husky/ + +# Environment variables +.env \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index f166d2309..1f8153001 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -31,12 +31,18 @@ import ( "github.com/apache/answer/internal/base/path" "github.com/apache/answer/internal/schema" "github.com/gin-gonic/gin" + "github.com/joho/godotenv" "github.com/segmentfault/pacman" "github.com/segmentfault/pacman/contrib/log/zap" "github.com/segmentfault/pacman/contrib/server/http" "github.com/segmentfault/pacman/log" ) +func init() { + // Load .env if present, ignore error to keep backward compatibility + _ = godotenv.Load() +} + // go build -ldflags "-X github.com/apache/answer/cmd.Version=x.y.z" var ( // Name is the name of the project diff --git a/go.mod b/go.mod index 969d9ebbc..52d64c738 100644 --- a/go.mod +++ b/go.mod @@ -117,6 +117,7 @@ require ( github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.8 // indirect diff --git a/go.sum b/go.sum index 35db004db..69d97751e 100644 --- a/go.sum +++ b/go.sum @@ -354,6 +354,8 @@ github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=