|
@@ -1,8 +1,10 @@
|
|
|
package tinymq
|
|
|
|
|
|
import (
|
|
|
+ "bytes"
|
|
|
"fmt"
|
|
|
"regexp"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -111,6 +113,29 @@ type HostInfo struct {
|
|
|
Updated time.Time `json:"updated" yaml:"updated"` // 节点信息刷新时间
|
|
|
}
|
|
|
|
|
|
+// 只输出客户端要连接的信息
|
|
|
+func (h *HostInfo) String() string {
|
|
|
+ var b bytes.Buffer
|
|
|
+ b.WriteString(fmt.Sprintf("%s%d://", h.Proto, h.Version))
|
|
|
+ if h.Hash != "" {
|
|
|
+ b.WriteString(h.Hash + "@")
|
|
|
+ }
|
|
|
+ if strings.Contains(h.Host, ":") {
|
|
|
+ // ipv6
|
|
|
+ b.WriteString("[" + h.Host + "]")
|
|
|
+ } else {
|
|
|
+ b.WriteString(h.Host)
|
|
|
+ }
|
|
|
+ b.WriteString(fmt.Sprintf(":%d", h.Port))
|
|
|
+ if h.Path != "" {
|
|
|
+ b.WriteString(h.Path)
|
|
|
+ }
|
|
|
+ if h.Proxy {
|
|
|
+ b.WriteString("?proxy=1")
|
|
|
+ }
|
|
|
+ return b.String()
|
|
|
+}
|
|
|
+
|
|
|
// 获取对应频道的一个连接地址
|
|
|
type ConnectHostFunc func(channel string) (hostInfo *HostInfo, err error)
|
|
|
|