forked from MR5356/elune-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (50 loc) · 1.55 KB
/
main.go
File metadata and controls
61 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"github.com/MR5356/elune-backend/pkg/config"
_ "github.com/MR5356/elune-backend/pkg/log"
"github.com/MR5356/elune-backend/pkg/server"
"github.com/MR5356/elune-backend/pkg/utils/structutil"
"github.com/sirupsen/logrus"
"os"
"strconv"
)
func main() {
var withs []config.Cfg
// 是否开启debug
if os.Getenv(config.EluneEnvDebug) == "true" {
logrus.SetLevel(logrus.DebugLevel)
withs = append(withs, config.WithDebug(true))
}
// 是否自定义端口
if len(os.Getenv(config.EluneEnvPort)) > 0 {
port, err := strconv.Atoi(os.Getenv(config.EluneEnvPort))
if err == nil {
withs = append(withs, config.WithPort(port))
} else {
logrus.Warnf("invalid port: %s", os.Getenv(config.EluneEnvPort))
}
}
// 是否定义数据库
if driver := os.Getenv(config.EluneEnvDatabaseDriver); len(driver) > 0 {
withs = append(withs, config.WithDatabaseDriver(driver))
}
if dsn := os.Getenv(config.EluneEnvDatabaseDSN); len(dsn) > 0 {
withs = append(withs, config.WithDatabaseDsn(dsn))
}
// 是否定义Cache
if driver := os.Getenv(config.EluneEnvCacheDriver); len(driver) > 0 {
withs = append(withs, config.WithCacheDriver(driver))
}
if dsn := os.Getenv(config.EluneEnvCacheDSN); len(dsn) > 0 {
withs = append(withs, config.WithCacheDsn(dsn))
}
cfg := config.New(withs...)
logrus.Debugf("run with config: %+v", structutil.Struct2String(cfg))
srv, err := server.New(cfg)
if err != nil {
logrus.Fatalf("create server error: %s", err)
}
if err := srv.Run(); err != nil {
logrus.Fatalf("run server error: %s", err)
}
}