| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package tinymq
- import (
- "reflect"
- "regexp"
- "runtime"
- "strings"
- )
- // 匹配所有的频道
- func AllChannelFilter() FilterFunc {
- return func(conn *Line) (ok bool) {
- return true
- }
- }
- // 正则频道过滤器
- func RegChannelFilter(channel *regexp.Regexp) FilterFunc {
- return func(conn *Line) (ok bool) {
- return channel.MatchString(conn.channel)
- }
- }
- // 字符串频道过滤器
- func StrChannelFilter(channel string) FilterFunc {
- return func(conn *Line) (ok bool) {
- return strings.Contains(conn.channel, channel)
- }
- }
- // 连接过滤器
- func LineLinkFilter(line *Line) FilterFunc {
- return func(conn *Line) (ok bool) {
- 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()
- }
|