|
|
|
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("1.92.109.79", 30848),
|
|
|
|
}
|
|
|
|
cc := constant.ClientConfig{
|
|
|
|
NamespaceId: "dev",
|
|
|
|
TimeoutMs: 5000,
|
|
|
|
}
|
|
|
|
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("1.92.109.79", 30848),
|
|
|
|
}
|
|
|
|
cc := constant.ClientConfig{
|
|
|
|
NamespaceId: "dev",
|
|
|
|
TimeoutMs: 5000,
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
// }()
|
|
|
|
|
|
|
|
}
|