1 Star 0 Fork 0

紫风天下行/慕课447-支付

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
紫风天下行 提交于 2022-03-18 09:44 . ok
package main
import (
"gitee.com/meinongyihe/common"
"gitee.com/meinongyihe/payment/domain/repository"
service2 "gitee.com/meinongyihe/payment/domain/service"
"gitee.com/meinongyihe/payment/handler"
payment "gitee.com/meinongyihe/payment/proto/payment"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/micro/go-micro/v2"
log "github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/registry"
consul2 "github.com/micro/go-plugins/registry/consul/v2"
prometheus "github.com/micro/go-plugins/wrapper/monitoring/prometheus/v2"
ratelimit "github.com/micro/go-plugins/wrapper/ratelimiter/uber/v2"
opentracing2 "github.com/micro/go-plugins/wrapper/trace/opentracing/v2"
"github.com/opentracing/opentracing-go"
)
func main() {
// 配置中心
consulConfig, err := common.GetConsulConfig("127.0.0.1", 8500, "/micro/config")
if err != nil {
common.Error(err)
}
//注册中心
consul := consul2.NewRegistry(func(options *registry.Options) {
options.Addrs = []string{
"127.0.0.1:8500",
}
})
//jaeger 链路追踪
t, io, err := common.NewTracer("go.micro.service.payment", "localhost:6831")
if err != nil {
common.Error(err)
}
defer io.Close()
opentracing.SetGlobalTracer(t)
//mysql 设置
mysqlInfo := common.GetMysqlFromConsul(consulConfig, "mysql")
//初始化数据库
db, err := gorm.Open("mysql", mysqlInfo.User+":"+mysqlInfo.Pwd+"@/"+mysqlInfo.Database+"?charset=utf8&parseTime=True&loc=Local")
if err != nil {
common.Error(err)
}
defer db.Close()
//禁止复数表
db.SingularTable(true)
//创建表
tableInit := repository.NewPaymentRepository(db)
tableInit.InitTable()
//监控
common.PrometheusBoot(9089)
// New Service
service := micro.NewService(
micro.Name("go.micro.service.payment"),
micro.Version("latest"),
//micro.Address("0.0.0.0:8089"),
//添加注册中心
micro.Registry(consul),
//添加链路追踪
micro.WrapHandler(opentracing2.NewHandlerWrapper(opentracing.GlobalTracer())),
//加载限流
micro.WrapHandler(ratelimit.NewHandlerWrapper(1000)),
//加载监控
micro.WrapHandler(prometheus.NewHandlerWrapper()),
)
// Initialise service
service.Init()
paymentDataService := service2.NewPaymentDataService(repository.NewPaymentRepository(db))
// Register Handler
payment.RegisterPaymentHandler(service.Server(), &handler.Payment{PaymentDataService: paymentDataService})
// Run service
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/meinongyihe/payment.git
git@gitee.com:meinongyihe/payment.git
meinongyihe
payment
慕课447-支付
master

搜索帮助