代码拉取完成,页面将自动刷新
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)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。