Skip to content

Commit 1fbb802

Browse files
maishivamhoo123LinkinStars
authored andcommitted
feat: load optional .env file and add .env.example
1 parent 5ff6106 commit 1fbb802

52 files changed

Lines changed: 86392 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Installation
2+
INSTALL_PORT=80
3+
AUTO_INSTALL=false
4+
5+
# Database
6+
DB_TYPE=
7+
DB_USERNAME=
8+
DB_PASSWORD=
9+
DB_HOST=
10+
DB_NAME=
11+
DB_FILE=
12+
13+
# Site
14+
LANGUAGE=en-US
15+
SITE_NAME=Apache Answer
16+
SITE_URL=
17+
CONTACT_EMAIL=
18+
19+
# Admin
20+
ADMIN_NAME=
21+
ADMIN_PASSWORD=
22+
ADMIN_EMAIL=
23+
24+
# Content
25+
EXTERNAL_CONTENT_DISPLAY=ask_before_display
26+
27+
# Swagger
28+
SWAGGER_HOST=
29+
SWAGGER_ADDRESS_PORT=
30+
31+
# Server
32+
SITE_ADDR=0.0.0.0:3000
33+
34+
# Logging
35+
LOG_LEVEL=INFO
36+
LOG_PATH=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ dist/
3333

3434
# Lint setup generated file
3535
.husky/
36+
37+
# Environment variables
38+
.env

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ You can also check out the [plugins here](https://answer.apache.org/plugins).
4646
- [mockgen](https://github.com/uber-go/mock?tab=readme-ov-file#installation) >= 0.6.0
4747
- [wire](https://github.com/google/wire/) >= 0.5.0
4848

49+
### Environment Configuration
50+
51+
You may create a `.env` file in the project root.
52+
Copy `.env.example` and fill required values.
53+
54+
```bash
55+
cp .env.example .env
56+
57+
4958
### Build
5059

5160
```bash

cmd/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ import (
3131
"github.com/apache/answer/internal/base/path"
3232
"github.com/apache/answer/internal/schema"
3333
"github.com/gin-gonic/gin"
34+
"github.com/joho/godotenv"
3435
"github.com/segmentfault/pacman"
3536
"github.com/segmentfault/pacman/contrib/log/zap"
3637
"github.com/segmentfault/pacman/contrib/server/http"
3738
"github.com/segmentfault/pacman/log"
3839
)
3940

41+
func init() {
42+
// Load .env if present, ignore error to keep backward compatibility
43+
_ = godotenv.Load()
44+
}
45+
4046
// go build -ldflags "-X github.com/apache/answer/cmd.Version=x.y.z"
4147
var (
4248
// Name is the name of the project

data/conf/config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
debug: false
2+
server:
3+
http:
4+
addr: 0.0.0.0:80
5+
data:
6+
database:
7+
driver: sqlite3
8+
connection: ./data/answer.db
9+
cache:
10+
file_path: data/cache/cache.db
11+
i18n:
12+
bundle_dir: data/i18n
13+
service_config:
14+
upload_path: data/uploads
15+
clean_up_uploads: true
16+
clean_orphan_uploads_period_hours: 48
17+
purge_deleted_files_period_days: 30
18+
swaggerui:
19+
show: true
20+
protocol: http
21+
host: 127.0.0.1
22+
address: :80
23+
ui:
24+
base_url: ""
25+
api_base_url: ""

0 commit comments

Comments
 (0)