zhangyinhao1234 opened a new issue, #47:
URL: https://github.com/apache/shenyu-client-golang/issues/47

   代码:
   package shenyu
   
   import (
        "encoding/json"
        "github.com/apache/shenyu-client-golang/clients/nacos_client"
        "github.com/apache/shenyu-client-golang/common/constants"
        "github.com/apache/shenyu-client-golang/common/shenyu_sdk_client"
        "github.com/apache/shenyu-client-golang/model"
        "github.com/nacos-group/nacos-sdk-go/clients/naming_client"
        "github.com/nacos-group/nacos-sdk-go/vo"
   
        "net"
        "pki-go-server/src/com/ifyou/pki/conf"
   )
   
   func RegisterShenYu() {
        //设置nacos环境配置
        ncp := &nacos_client.NacosClientParam{
                IpAddr:      "10.246.162.117",
                Port:        18848,
                NamespaceId: "d1bd133f-f415-404b-8e2c-60847ce426d4",
        }
   
        //元数据是必要的参数,这将注册到shenyu网关使用
        metaData := &model.URIRegister{
                Protocol:    "http",                 //需要用户提供
                AppName:     "pki-go-server",        //需要用户提供
                ContextPath: "/godemo/api",          //需要用户提供
                RPCType:     constants.RPCTYPE_HTTP, //需要用户提供
                Host:        getLocalIP(),           //需要用户提供
                Port:        "8080",                 //需要用户提供
        }
        metaDataStringJson, _ := json.Marshal(metaData)
   
        //初始化Nacos注册实例信息
        nacosRegisterInstance := vo.RegisterInstanceParam{
                Ip:          "10.246.162.117", //需要用户提供
                Port:        18848,            //需要用户提供
                ServiceName: "pki-go-server",  //需要用户提供
                Weight:      10,               //需要用户提供
                Enable:      true,             //需要用户提供
                Healthy:     true,             //需要用户提供
                Ephemeral:   true,             //需要用户提供
                Metadata:    map[string]string{"contextPath": "contextPath", 
"uriMetadata": string(metaDataStringJson)},
        }
   
        sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT)
        result, createResult, err := sdkClient.NewClient(ncp)
        if !createResult && err != nil {
                conf.LogEntry.Fatalf("Create nacos client error : %v", err)
        }
   
        nc := &nacos_client.ShenYuNacosClient{
                NacosClient: result.(*naming_client.NamingClient),
        }
   
        registerResult, err := nc.RegisterServiceInstance(nacosRegisterInstance)
        if !registerResult && err != nil {
                conf.LogEntry.Fatalf("Register nacos Instance error : %v", err)
        } else {
                conf.LogEntry.Infof("Register nacos Instance success : %v", 
registerResult)
        }
   
        //do your logic
   
   }
   
   func getLocalIP() string {
        addrs, err := net.InterfaceAddrs()
        if err != nil {
                return "unknow"
        }
   
        for _, address := range addrs {
                if ipnet, ok := address.(*net.IPNet); ok && 
!ipnet.IP.IsLoopback() {
                        if ipnet.IP.To4() != nil {
                                gInnerIP := ipnet.IP.String()
                                return gInnerIP
                        }
                }
        }
        return "unknow"
   }
   
   
   
   
   
   2024-04-07T15:03:16.118+0800    ERROR   nacos_server/nacos_server.go:230     
   api</v1/ns/instance>,method:<POST>, 
params:<{"app":"","clusterName":"","enable":"true","ephemeral":"true","groupName":"DEFAULT_GROUP","healthy":"true","ip":"10.246.162.117","metadata":"{\"contextPath\":\"contextPath\",\"uriMetadata\":\"{\\\"protocol\\\":\\\"http\\\",\\\"appName\\\":\\\"pki-go-server\\\",\\\"contextPath\\\":\\\"/godemo/api\\\",\\\"rpcType\\\":\\\"http\\\",\\\"host\\\":\\\"192.168.137.59\\\",\\\"port\\\":\\\"8080\\\"}\"}","namespaceId":"d1bd133f-f415-404b-8e2c-60847ce426d4","port":"18848","serviceName":"DEFAULT_GROUP@@pki-go-server","weight":"10"}>,
 call domain error:<request return error code 403> , 
result:<{"timestamp":"2024-04-07T15:03:11.808+08:00","status":403,"error":"Forbidden","message":"unknown
 user!","path":"/nacos/v1/ns/instance"}>
   FATA[0004] RegisterServiceInstance failure! ,error is :retry3times request 
failed,err=request return error code 403 
   
   
   可能的原始是否为,Nacos需要用户名密码登陆. shenyu-sdk使用的是Nacos 1V的包,导致无法注册 抛出403?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to