You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.6 KiB
115 lines
2.6 KiB
6 months ago
|
package initialize
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"shop-api/global"
|
||
|
"shop-api/initialize/api"
|
||
|
"time"
|
||
|
|
||
|
"github.com/go-kratos/kratos/contrib/registry/nacos/v2"
|
||
|
"github.com/go-kratos/kratos/v2/middleware/recovery"
|
||
|
"github.com/go-kratos/kratos/v2/transport/grpc"
|
||
|
"github.com/nacos-group/nacos-sdk-go/clients"
|
||
|
"github.com/nacos-group/nacos-sdk-go/common/constant"
|
||
|
"github.com/nacos-group/nacos-sdk-go/vo"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
sc := []constant.ServerConfig{
|
||
|
*constant.NewServerConfig("72535c70-8d6d-400f-9893-4bb3e634f682.nacos.cn-north-4.cse.myhuaweicloud.com", 8848),
|
||
|
}
|
||
|
cc := constant.ClientConfig{
|
||
|
NamespaceId: "dev",
|
||
|
TimeoutMs: 5000,
|
||
|
Username: "nacos",
|
||
|
Password: "nacos",
|
||
|
}
|
||
|
client, err := clients.NewNamingClient(
|
||
|
vo.NacosClientParam{
|
||
|
ServerConfigs: sc,
|
||
|
ClientConfig: &cc,
|
||
|
},
|
||
|
)
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
panic(err)
|
||
|
}
|
||
|
r := nacos.New(client)
|
||
|
conn, err := grpc.DialInsecure(
|
||
|
context.Background(),
|
||
|
grpc.WithEndpoint("discovery:///bkb.payment.grpc"),
|
||
|
grpc.WithDiscovery(r),
|
||
|
grpc.WithMiddleware(recovery.Recovery()),
|
||
|
grpc.WithTimeout(10*time.Second),
|
||
|
)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
global.PAY_CONN = conn
|
||
|
}
|
||
|
|
||
|
func InitNacosClient() {
|
||
|
sc := []constant.ServerConfig{
|
||
|
*constant.NewServerConfig("72535c70-8d6d-400f-9893-4bb3e634f682.nacos.cn-north-4.cse.myhuaweicloud.com", 8848),
|
||
|
}
|
||
|
cc := constant.ClientConfig{
|
||
|
NamespaceId: "dev",
|
||
|
TimeoutMs: 5000,
|
||
|
Username: "nacos",
|
||
|
Password: "nacos",
|
||
|
}
|
||
|
func() {
|
||
|
client, err := clients.NewNamingClient(
|
||
|
vo.NacosClientParam{
|
||
|
ServerConfigs: sc,
|
||
|
ClientConfig: &cc,
|
||
|
},
|
||
|
)
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
panic(err)
|
||
|
}
|
||
|
r := nacos.New(client)
|
||
|
ctx, cel := context.WithTimeout(context.Background(), time.Second*5)
|
||
|
defer cel()
|
||
|
conn, err := grpc.DialInsecure(
|
||
|
ctx,
|
||
|
grpc.WithEndpoint("discovery:///bkb.notify.grpc"),
|
||
|
grpc.WithDiscovery(r),
|
||
|
grpc.WithMiddleware(
|
||
|
recovery.Recovery()))
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
global.EMAIL_CLIENT = api.NewEmailClient(conn)
|
||
|
global.SMS_CLIENT = api.NewSmsClient(conn)
|
||
|
}()
|
||
|
// func() {
|
||
|
// client, err := clients.NewNamingClient(
|
||
|
// vo.NacosClientParam{
|
||
|
// ServerConfigs: sc,
|
||
|
// ClientConfig: &cc,
|
||
|
// },
|
||
|
// )
|
||
|
// if err != nil {
|
||
|
// fmt.Println(err)
|
||
|
// panic(err)
|
||
|
// }
|
||
|
// r := nacos.New(client)
|
||
|
// ctx, cel := context.WithTimeout(context.Background(), time.Second*5)
|
||
|
// defer cel()
|
||
|
// conn, err := grpc.DialInsecure(
|
||
|
// ctx,
|
||
|
// grpc.WithEndpoint("discovery:///bkb.notify.grpc"),
|
||
|
// grpc.WithDiscovery(r),
|
||
|
// grpc.WithMiddleware(
|
||
|
// recovery.Recovery()))
|
||
|
// if err != nil {
|
||
|
// panic(err)
|
||
|
// }
|
||
|
// global.SMS_CLIENT = api.NewSmsClient(conn)
|
||
|
// }()
|
||
|
|
||
|
}
|