|
|
@@ -10,9 +10,20 @@ import (
|
|
|
"dashoo.cn/opms_libary/request"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
+ "github.com/gogf/gf/encoding/gbase64"
|
|
|
+ "github.com/gogf/gf/encoding/gjson"
|
|
|
"github.com/gogf/gf/errors/gerror"
|
|
|
+ "github.com/gogf/gf/frame/g"
|
|
|
+ "github.com/gogf/gf/net/ghttp"
|
|
|
+ "github.com/gogf/gf/text/gstr"
|
|
|
"github.com/gogf/gf/util/gconv"
|
|
|
"github.com/rcrowley/go-metrics"
|
|
|
+ consulclient "github.com/rpcxio/rpcx-consul/client"
|
|
|
+ "github.com/rpcxio/rpcx-consul/serverplugin"
|
|
|
+ "github.com/smallnest/rpcx/client"
|
|
|
+ "github.com/smallnest/rpcx/protocol"
|
|
|
+ "github.com/smallnest/rpcx/server"
|
|
|
+ "github.com/smallnest/rpcx/share"
|
|
|
"io/ioutil"
|
|
|
"net"
|
|
|
"os"
|
|
|
@@ -20,17 +31,6 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
-
|
|
|
- "github.com/gogf/gf/encoding/gbase64"
|
|
|
- "github.com/gogf/gf/encoding/gjson"
|
|
|
- "github.com/gogf/gf/frame/g"
|
|
|
- "github.com/gogf/gf/net/ghttp"
|
|
|
- "github.com/gogf/gf/text/gstr"
|
|
|
- "github.com/smallnest/rpcx/client"
|
|
|
- "github.com/smallnest/rpcx/protocol"
|
|
|
- "github.com/smallnest/rpcx/server"
|
|
|
- "github.com/smallnest/rpcx/serverplugin"
|
|
|
- "github.com/smallnest/rpcx/share"
|
|
|
)
|
|
|
|
|
|
// InitMicroSrvClient 获取微服务客户端,arg为可选参数,若有必须是两个,分别是:reg string, serverAddr string
|
|
|
@@ -52,7 +52,8 @@ func InitMicroSrvClient(serviceName, key string, args ...string) (c client.XClie
|
|
|
} else {
|
|
|
if reg == "consul" { // 服务发现使用consul
|
|
|
//d, _ := etcd_client.NewEtcdV3Discovery(srvName, serviceName, []string{etcdAddr}, nil)
|
|
|
- d, _ := client.NewConsulDiscovery(srvName, serviceName, []string{etcdAddr}, nil)
|
|
|
+ d, _ := consulclient.NewConsulDiscovery(srvName, serviceName, []string{etcdAddr}, nil)
|
|
|
+ //d, _ := client.NewConsulDiscovery(srvName, serviceName, []string{etcdAddr}, nil)
|
|
|
c = client.NewXClient(serviceName, client.Failover, client.RoundRobin, d, client.DefaultOption)
|
|
|
return c
|
|
|
}
|
|
|
@@ -180,11 +181,20 @@ func streamHandler(conn net.Conn, args *share.StreamServiceArgs) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+func getTenant(msg *protocol.Message) string {
|
|
|
+ var tenant string
|
|
|
+ if msg.Metadata != nil {
|
|
|
+ tenant = msg.Metadata["tenant"]
|
|
|
+ }
|
|
|
+ return tenant
|
|
|
+}
|
|
|
+
|
|
|
// HandleAuth 处理Auth认证
|
|
|
func HandleAuth(ctx context.Context, req *protocol.Message, token string, authExcludePaths []string) error {
|
|
|
path := "/" + req.ServicePath + "/" + req.ServiceMethod
|
|
|
//g.Log().Info("reqPath: ", path)
|
|
|
//g.Log().Info("token: ", token)
|
|
|
+ g.Log().Info("Received " + path + " request @ " + getTenant(req))
|
|
|
|
|
|
if authPath(path, authExcludePaths) {
|
|
|
req.Metadata["authExclude"] = "false"
|