-
Notifications
You must be signed in to change notification settings - Fork 62
/
main.go
66 lines (50 loc) · 1.39 KB
/
main.go
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
62
63
64
65
66
package main
import (
_ "embed"
"io"
"strconv"
"github.com/nitezs/sub2clash/api"
"github.com/nitezs/sub2clash/common"
"github.com/nitezs/sub2clash/common/database"
"github.com/nitezs/sub2clash/config"
"github.com/nitezs/sub2clash/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
//go:embed templates/template_meta.yaml
var templateMeta string
//go:embed templates/template_clash.yaml
var templateClash string
func init() {
var err error
err = common.MkEssentialDir()
if err != nil {
logger.Logger.Panic("create essential dir failed", zap.Error(err))
}
err = config.LoadConfig()
logger.InitLogger(config.Default.LogLevel)
if err != nil {
logger.Logger.Panic("load config failed", zap.Error(err))
}
err = common.WriteDefalutTemplate(templateMeta, templateClash)
if err != nil {
logger.Logger.Panic("write default template failed", zap.Error(err))
}
err = database.ConnectDB()
if err != nil {
logger.Logger.Panic("database connect failed", zap.Error(err))
}
logger.Logger.Info("database connect success")
}
func main() {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard
r := gin.Default()
api.SetRoute(r)
logger.Logger.Info("server is running at http://localhost:" + strconv.Itoa(config.Default.Port))
err := r.Run(":" + strconv.Itoa(config.Default.Port))
if err != nil {
logger.Logger.Error("server running failed", zap.Error(err))
return
}
}