2021-03-23 00:55:26 +08:00
|
|
|
/*
|
|
|
|
* @Date: 2021-03-21 19:54:57
|
|
|
|
* @LastEditors: viletyy
|
2021-07-08 14:05:14 +08:00
|
|
|
* @LastEditTime: 2021-07-08 13:59:06
|
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"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/soheilhy/cmux"
|
2021-03-23 00:55:26 +08:00
|
|
|
"github.com/viletyy/potato/global"
|
|
|
|
"github.com/viletyy/potato/initialize"
|
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-06-20 19:29:27 +08:00
|
|
|
var port string
|
|
|
|
|
|
|
|
func runTcpServer(port string) (net.Listener, error) {
|
|
|
|
return net.Listen("tcp", ":"+port)
|
|
|
|
}
|
|
|
|
|
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-08 14:05:14 +08:00
|
|
|
initialize.Cron()
|
2019-08-07 20:56:20 +08:00
|
|
|
|
2021-03-23 00:55:26 +08:00
|
|
|
defer global.GO_DB.Close()
|
|
|
|
defer global.GO_REDIS.Close()
|
2019-08-07 20:56:20 +08:00
|
|
|
|
2021-06-20 19:47:08 +08:00
|
|
|
flag.StringVar(&port, "port", convert.ToString(global.GO_CONFIG.Server.Port), "启动端口号")
|
2021-06-20 19:29:27 +08:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
l, err := runTcpServer(port)
|
|
|
|
if err != nil {
|
|
|
|
global.GO_LOG.Sugar().Fatalf("Run Tcp Server err: %v", err)
|
|
|
|
}
|
|
|
|
m := cmux.New(l)
|
|
|
|
grpcL := m.MatchWithWriters(
|
|
|
|
cmux.HTTP2MatchHeaderFieldSendSettings(
|
|
|
|
"content-type",
|
|
|
|
"application/grpc",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
httpL := m.Match(cmux.HTTP1Fast())
|
|
|
|
|
|
|
|
grpcS := initialize.RunGrpcServer()
|
|
|
|
httpS := initialize.RunServer(port)
|
|
|
|
go grpcS.Serve(grpcL)
|
|
|
|
go httpS.Serve(httpL)
|
|
|
|
|
|
|
|
err = m.Serve()
|
|
|
|
if err != nil {
|
|
|
|
global.GO_LOG.Sugar().Fatalf("Run Server err: %v", err)
|
|
|
|
}
|
2019-08-07 20:56:20 +08:00
|
|
|
|
2021-03-23 00:55:26 +08:00
|
|
|
}
|