Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9076ec5c
authored
Sep 24, 2024
by
lianghaoyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加.env配置文件和初始化环境变量
parent
e3620c1c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
7 deletions
+101
-7
.env.example
+84
-0
.gitignore
+2
-2
go.mod
+1
-0
go.sum
+2
-0
main.go
+12
-5
No files found.
.env.example
0 → 100644
View file @
9076ec5c
# 端口号
PORT=3000
# 前端基础URL
FRONTEND_BASE_URL=https://your-frontend-url.com
# 调试相关配置
# 调试模式
DEBUG=true
# 启用pprof
ENABLE_PPROF=true
# 内存缓存启用
MEMORY_CACHE_ENABLED=true
# 数据库相关配置
# 数据库连接字符串
SQL_DSN=mysql://user:password@tcp(127.0.0.1:3306)/dbname?parseTime=true
# 日志数据库连接字符串
LOG_SQL_DSN=mysql://user:password@tcp(127.0.0.1:3306)/logdb?parseTime=true
# SQLite数据库路径
SQLITE_PATH=/path/to/sqlite.db
# 数据库最大空闲连接数
SQL_MAX_IDLE_CONNS=100
# 数据库最大打开连接数
SQL_MAX_OPEN_CONNS=1000
# 数据库连接最大生命周期(秒)
SQL_MAX_LIFETIME=60
# Redis相关配置
# Redis连接字符串
REDIS_CONN_STRING=redis://user:password@localhost:6379/0
# 同步频率(单位:秒)
SYNC_FREQUENCY=60
# 会话相关配置
# 会话秘密
SESSION_SECRET=random_string
# 任务和功能配置
# 批量更新启用
BATCH_UPDATE_ENABLED=true
# 批量更新间隔(单位:秒)
BATCH_UPDATE_INTERVAL=5
# 更新任务启用
UPDATE_TASK=true
# 禁用通道阈值
CHANNEL_DISABLE_THRESHOLD=5.0
# 其他配置
# 通道更新频率(单位:秒)
CHANNEL_UPDATE_FREQUENCY=30
# 通道测试频率(单位:秒)
CHANNEL_TEST_FREQUENCY=10
# 生成默认令牌
GENERATE_DEFAULT_TOKEN=false
# 气候模式设置
GEMINI_SAFETY_SETTING=BLOCK_NONE
# 文本生成安全设置
COHERE_SAFETY_SETTING=NONE
# 节点类型
# 如果是主节点则为true
NODE_TYPE=master
# SMTP配置(可选)
# SMTP服务器地址
SMTP_SERVER=smtp.example.com
# SMTP端口
SMTP_PORT=587
# 是否启用SMTP SSL
SMTP_SSL_ENABLED=false
# SMTP账户
SMTP_ACCOUNT=user@example.com
# SMTP发件人地址
SMTP_FROM=admin@example.com
# SMTP令牌
SMTP_TOKEN=your-smtp-token
.gitignore
View file @
9076ec5c
...
...
@@ -6,4 +6,5 @@ upload
build
*.db-journal
logs
web/dist
\ No newline at end of file
web/dist
.env
go.mod
View file @
9076ec5c
...
...
@@ -63,6 +63,7 @@ require (
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
...
...
go.sum
View file @
9076ec5c
...
...
@@ -111,6 +111,8 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
...
...
main.go
View file @
9076ec5c
...
...
@@ -3,10 +3,6 @@ package main
import
(
"embed"
"fmt"
"github.com/bytedance/gopkg/util/gopool"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"log"
"net/http"
"one-api/common"
...
...
@@ -19,6 +15,12 @@ import (
"os"
"strconv"
"github.com/bytedance/gopkg/util/gopool"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
_
"net/http/pprof"
)
...
...
@@ -29,6 +31,11 @@ var buildFS embed.FS
var
indexPage
[]
byte
func
main
()
{
err
:=
godotenv
.
Load
(
".env"
)
if
err
!=
nil
{
common
.
SysLog
(
"Can't load .env file"
)
}
common
.
SetupLogger
()
common
.
SysLog
(
"New API "
+
common
.
Version
+
" started"
)
if
os
.
Getenv
(
"GIN_MODE"
)
!=
"debug"
{
...
...
@@ -38,7 +45,7 @@ func main() {
common
.
SysLog
(
"running in debug mode"
)
}
// Initialize SQL Database
err
:
=
model
.
InitDB
()
err
=
model
.
InitDB
()
if
err
!=
nil
{
common
.
FatalLog
(
"failed to initialize database: "
+
err
.
Error
())
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment