Joyit 4 недель назад
Родитель
Сommit
9ffeda24af
3 измененных файлов с 29 добавлено и 15 удалено
  1. 9 9
      config/const.go
  2. 14 0
      filter.go
  3. 6 6
      hub.go

+ 9 - 9
config/const.go

@@ -9,9 +9,9 @@ const (
 	FORBIDDEN             = 120
 	FORBIDDEN             = 120
 	SYSTEM_ERROR          = 123
 	SYSTEM_ERROR          = 123
 	GET_TIMEOUT           = 124
 	GET_TIMEOUT           = 124
-	CONNECT_NO_MATCH      = 125
-	CONNECT_END           = 126
-	NO_MATCH              = 127
+	NO_MATCH_CONNECT      = 125
+	NO_MATCH_FILTER       = 126
+	NO_MATCH_CMD          = 127
 	MAX_SYSTEM_ERROR_CODE = 127 //系统信息最大值
 	MAX_SYSTEM_ERROR_CODE = 127 //系统信息最大值
 )
 )
 
 
@@ -30,12 +30,12 @@ func IdMsg(id int) string {
 		return "SYSTEM ERROR"
 		return "SYSTEM ERROR"
 	case GET_TIMEOUT:
 	case GET_TIMEOUT:
 		return "GET TIMEOUT"
 		return "GET TIMEOUT"
-	case CONNECT_NO_MATCH:
-		return "CONNECT NO MATCH"
-	case CONNECT_END:
-		return "CONNECT END"
-	case NO_MATCH:
-		return "NO MATCH"
+	case NO_MATCH_CONNECT:
+		return "NO MATCH CONNECT"
+	case NO_MATCH_FILTER:
+		return "NO MATCH FILTER"
+	case NO_MATCH_CMD:
+		return "NO MATCH CMD"
 	}
 	}
 	return "UNKNOWN"
 	return "UNKNOWN"
 }
 }

+ 14 - 0
filter.go

@@ -1,7 +1,9 @@
 package tinymq
 package tinymq
 
 
 import (
 import (
+	"reflect"
 	"regexp"
 	"regexp"
+	"runtime"
 	"strings"
 	"strings"
 )
 )
 
 
@@ -32,3 +34,15 @@ func LineLinkFilter(line *Line) FilterFunc {
 		return line == conn
 		return line == conn
 	}
 	}
 }
 }
+
+// GetFunctionName returns the fully qualified name of the function passed as an interface.
+func GetFunctionName(temp any) string {
+	// Use reflect to get the pointer to the function's code.
+	pc := reflect.ValueOf(temp).Pointer()
+	// Use runtime.FuncForPC to get function details.
+	f := runtime.FuncForPC(pc)
+	if f == nil {
+		return ""
+	}
+	return f.Name()
+}

+ 6 - 6
hub.go

@@ -419,8 +419,8 @@ func (h *Hub) requestFromNet(request *RequestData) {
 	// 返回没有匹配的消息
 	// 返回没有匹配的消息
 	request.conn.sendResponse <- &ResponseData{
 	request.conn.sendResponse <- &ResponseData{
 		Id:    request.Id,
 		Id:    request.Id,
-		State: config.NO_MATCH,
-		Data:  fmt.Appendf(nil, "[%s] %s %s", config.IdMsg(config.NO_MATCH), channel, cmd),
+		State: config.NO_MATCH_CMD,
+		Data:  fmt.Appendf(nil, "[%s] Channel: %s, Cmd: %s", config.IdMsg(config.NO_MATCH_CMD), channel, cmd),
 	}
 	}
 }
 }
 
 
@@ -493,8 +493,8 @@ func (h *Hub) Get(filter FilterFunc, cmd string, data any, backFunc GetBackFunc)
 func (h *Hub) GetOneWithStruct(gd *GetData) (response *ResponseData) {
 func (h *Hub) GetOneWithStruct(gd *GetData) (response *ResponseData) {
 	if gd.Filter == nil {
 	if gd.Filter == nil {
 		return &ResponseData{
 		return &ResponseData{
-			State: config.CONNECT_NO_MATCH,
-			Data:  fmt.Appendf(nil, "[%s] not filter function", config.IdMsg(config.CONNECT_NO_MATCH)),
+			State: config.NO_MATCH_FILTER,
+			Data:  fmt.Appendf(nil, "[%s] not filter function", config.IdMsg(config.NO_MATCH_FILTER)),
 		}
 		}
 	}
 	}
 	gd.Max = 1
 	gd.Max = 1
@@ -504,8 +504,8 @@ func (h *Hub) GetOneWithStruct(gd *GetData) (response *ResponseData) {
 	})
 	})
 	if response == nil {
 	if response == nil {
 		return &ResponseData{
 		return &ResponseData{
-			State: config.CONNECT_NO_MATCH,
-			Data:  fmt.Appendf(nil, "[%s] %s", config.IdMsg(config.CONNECT_NO_MATCH), gd.Cmd),
+			State: config.NO_MATCH_CONNECT,
+			Data:  fmt.Appendf(nil, "[%s] Filter: %s, Cmd: %s", config.IdMsg(config.NO_MATCH_CONNECT), GetFunctionName(gd.Filter), gd.Cmd),
 		}
 		}
 	}
 	}
 	return
 	return