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.
55 lines
1.2 KiB
55 lines
1.2 KiB
9 months ago
|
package initialize
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"github.com/go-kratos/kratos/contrib/registry/nacos/v2"
|
||
|
"pure-admin/global"
|
||
|
"pure-admin/initialize/api"
|
||
|
"time"
|
||
|
|
||
|
"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",
|
||
|
}
|
||
|
func() {
|
||
|
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_CLIENT = api.NewGreeterClient(conn)
|
||
|
}()
|
||
|
}
|