potato/main.go

83 lines
2.0 KiB
Go
Raw Permalink Normal View History

2021-03-23 00:55:26 +08:00
/*
* @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy
2021-07-09 14:48:22 +08:00
* @LastEditTime: 2021-07-09 14:37:35
2021-03-23 00:55:26 +08:00
* @FilePath: /potato/main.go
*/
2019-08-07 20:56:20 +08:00
package main
import (
2021-06-20 19:29:27 +08:00
"flag"
2021-03-23 00:55:26 +08:00
"github.com/viletyy/potato/global"
"github.com/viletyy/potato/initialize"
2022-07-15 19:04:33 +08:00
"github.com/viletyy/potato/migrations"
2021-06-20 19:29:27 +08:00
"github.com/viletyy/yolk/convert"
2019-08-07 20:56:20 +08:00
)
// @title Potato Api
// @version 1.0
2021-06-10 15:37:36 +08:00
// @description This is a potato use golang
2019-08-07 20:56:20 +08:00
// @BasePath /api
2021-07-09 14:48:22 +08:00
var grpcPort string
var httpPort string
2021-06-20 19:29:27 +08:00
2019-08-07 20:56:20 +08:00
func main() {
2021-03-23 00:55:26 +08:00
global.GO_VP = initialize.Viper()
global.GO_LOG = initialize.Zap()
global.GO_DB = initialize.Gorm()
global.GO_REDIS = initialize.Redis()
2021-06-14 21:15:55 +08:00
global.GO_TRACER = initialize.Tracer()
2021-07-09 14:48:22 +08:00
go initialize.Cron()
2019-08-07 20:56:20 +08:00
2022-07-15 19:04:33 +08:00
if err := migrations.Migrate(global.GO_DB); err != nil {
global.GO_LOG.Sugar().Fatalf("migrations.Migrate: %v", err)
}
sqlDB, err := global.GO_DB.DB()
if err != nil {
global.GO_LOG.Sugar().Fatalf("global.GO_DB.DB err: %v", err)
}
defer sqlDB.Close()
2021-03-23 00:55:26 +08:00
defer global.GO_REDIS.Close()
2019-08-07 20:56:20 +08:00
2021-07-09 14:48:22 +08:00
flag.StringVar(&grpcPort, "grpc_port", convert.ToString(global.GO_CONFIG.Server.GrpcPort), "启动grpc服务端口号")
flag.StringVar(&httpPort, "http_port", convert.ToString(global.GO_CONFIG.Server.HttpPort), "启动http服务端口号")
2021-06-20 19:29:27 +08:00
2021-07-09 14:48:22 +08:00
flag.Parse()
2021-06-20 19:29:27 +08:00
2022-07-15 19:04:33 +08:00
// defaultMailer := email.NewEmail(&email.SMTPInfo{
// Host: global.GO_CONFIG.Email.Host,
// Port: global.GO_CONFIG.Email.Port,
// IsSSL: global.GO_CONFIG.Email.IsSSL,
// UserName: global.GO_CONFIG.Email.UserName,
// Password: global.GO_CONFIG.Email.Password,
// From: global.GO_CONFIG.Email.From,
// })
// _ = defaultMailer.SendMail(
// global.GO_CONFIG.Email.To,
// fmt.Sprintf("异常抛出,发生时间:%d", time.Now().Unix()),
// fmt.Sprintf("错误信息heheh%s", "dfds"),
// )
2021-07-09 14:48:22 +08:00
errs := make(chan error)
go func() {
err := initialize.RunHttpServer(httpPort)
if err != nil {
errs <- err
}
}()
go func() {
err := initialize.RunGrpcServer(grpcPort)
if err != nil {
errs <- err
}
}()
select {
case err := <-errs:
2021-06-20 19:29:27 +08:00
global.GO_LOG.Sugar().Fatalf("Run Server err: %v", err)
}
2021-03-23 00:55:26 +08:00
}