1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 15:14:43 -05:00
sub2clash/main.go

66 lines
1.3 KiB
Go
Raw Normal View History

2023-09-12 06:40:24 -04:00
package main
import (
_ "embed"
2023-09-13 01:47:22 -04:00
"io"
2023-09-12 12:46:17 -04:00
"strconv"
"sub2clash/api"
"sub2clash/common"
"sub2clash/common/database"
2023-09-12 12:46:17 -04:00
"sub2clash/config"
2023-09-13 01:47:22 -04:00
"sub2clash/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
2023-09-12 06:40:24 -04:00
)
2023-09-12 12:46:17 -04:00
//go:embed templates/template_meta.yaml
2023-09-12 06:40:24 -04:00
var templateMeta string
2023-09-12 12:46:17 -04:00
//go:embed templates/template_clash.yaml
2023-09-12 06:40:24 -04:00
var templateClash string
func init() {
var err error
2024-08-11 11:55:47 -04:00
err = common.MkEssentialDir()
if err != nil {
logger.Logger.Panic("create essential dir failed", zap.Error(err))
}
2024-08-11 11:55:47 -04:00
err = config.LoadConfig()
2024-08-11 11:55:47 -04:00
logger.InitLogger(config.Default.LogLevel)
if err != nil {
logger.Logger.Panic("load config failed", zap.Error(err))
2023-09-12 06:40:24 -04:00
}
2024-08-11 11:55:47 -04:00
err = common.WriteDefalutTemplate(templateMeta, templateClash)
if err != nil {
logger.Logger.Panic("write default template failed", zap.Error(err))
2023-09-12 06:40:24 -04:00
}
2024-08-11 11:55:47 -04:00
err = database.ConnectDB()
2023-09-17 03:52:37 -04:00
if err != nil {
logger.Logger.Panic("database connect failed", zap.Error(err))
2023-09-17 03:52:37 -04:00
}
logger.Logger.Info("database connect success")
2023-09-12 06:40:24 -04:00
}
func main() {
2024-08-11 11:55:47 -04:00
2023-09-12 06:40:24 -04:00
gin.SetMode(gin.ReleaseMode)
2024-08-11 11:55:47 -04:00
2023-09-13 01:47:22 -04:00
gin.DefaultWriter = io.Discard
2024-08-11 11:55:47 -04:00
2023-09-12 06:40:24 -04:00
r := gin.Default()
2024-08-11 11:55:47 -04:00
2023-09-12 06:40:24 -04:00
api.SetRoute(r)
logger.Logger.Info("server is running at http://localhost:" + strconv.Itoa(config.Default.Port))
2023-09-12 12:46:17 -04:00
err := r.Run(":" + strconv.Itoa(config.Default.Port))
2023-09-12 06:40:24 -04:00
if err != nil {
logger.Logger.Error("server running failed", zap.Error(err))
2023-09-12 06:40:24 -04:00
return
}
}