feat: 添加.env配置文件和初始化环境变量

This commit is contained in:
lianghaoyuan
2024-09-24 11:39:02 +08:00
parent 50eab6b4e4
commit 84f40b63b2
5 changed files with 101 additions and 6 deletions

17
main.go
View File

@@ -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())
}