-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
111 lines (96 loc) · 3.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
gs "github.com/Idiotmann/edge/algorithm"
"github.com/Idiotmann/edge/model"
"github.com/Idiotmann/edge/plotEva"
"github.com/go-micro/plugins/v4/registry/consul"
opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing"
"github.com/opentracing/opentracing-go"
"go-micro.dev/v4"
"go-micro.dev/v4/registry"
"log"
)
var GS gs.GS
func main() {
//配置中心
consulConfig, err := common.GetConsulConfig("127.0.0.1", 8500, "micro/config")
if err != nil {
log.Fatal(err)
}
//注册中心
consulReg := consul.NewRegistry(func(options *registry.Options) {
options.Addrs = []string{"127.0.0.1:8500"}
})
//链路追踪
t, io, err := common.NewTracer("go.micro.service.product", "localhost:6831")
if err != nil {
log.Fatal(err)
}
defer io.Close()
opentracing.SetGlobalTracer(t)
//获取mysql配置,路径中不带前缀
//mysql需要手动加载数据库驱动
//mysqlConfig, err := common.GetMysqlFromConsul(consulConfig, "mysql")
//if err != nil {
// log.Fatal(err)
//}
//// 数据库类型:mysql,数据库用户名:root,密码:Kk1503060325,数据库名字:micro
//db, err := gorm.Open("mysql", mysqlConfig.User+":"+mysqlConfig.Password+"@/"+mysqlConfig.Database+"?charset=utf8&parseTime=True&loc=Local")
//if err != nil {
// log.Fatal(err)
//}
//defer db.Close()
//db.SingularTable(true) //禁用表名复数
//
////创建表之后,就注释掉
////repository.NewProductRepository(db).InitTable()
//productDataService := service2.NewProductDataService(repository.NewProductRepository(db))
service := micro.NewService(
micro.Name("go.micro.service.product"),
micro.Version("latest"),
micro.Address("127.0.0.1:8085"), //服务启动的地址
micro.Registry(consulReg), //注册中心
//绑定链路追踪 服务端绑定handler,客户端绑定Client
micro.WrapHandler(opentracing2.NewHandlerWrapper(opentracing.GlobalTracer())),
)
//获取mysql配置,路径中不带前缀
//mysql需要手动加载数据库驱动
// Initialise service
service.Init()
// Register Handler
pb.RegisterProductHandler(service.Server(), &handler.Product{ProductDataService: productDataService})
if err != nil {
log.Fatal(err)
}
// Run service
if err := service.Run(); err != nil {
log.Fatal(err)
}
girlIp := model.GirlIP{"w1", "w2", "w3", "w4"}
boyIp := model.BoyIP{"m1", "m2", "m3"}
// 将数据存储按cost排序存储
wbgList, _ := model.Compile(boyIp, girlIp) // 生成数据
for _, v := range wbgList {
//fmt.Printf("Graph长度是=%v \n", len(v.Graph))
graph := v.Graph
//创建people数据
boyArr1, girlArr1 := gs.SortLike(graph)
for i, k := range v.Graph {
fmt.Printf("Graph[%v]宽度是=%v \n", i, len(k))
for j, m := range k {
fmt.Printf("Graph[%v][%v]=%v \n", i, j, m)
}
}
index := GS.GaleShapley(boyArr1, girlArr1)
fmt.Println("名字:\t最终匹配对象:")
for _, v := range boyArr1 {
fmt.Printf("%v\t%v\t\n", v.Name, v.Friend)
}
fmt.Println("")
for _, v := range girlArr1 {
fmt.Printf("%v\t%v\n", v.Name, v.Friend)
}
plotEva.Plot(index)
}
}