-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubject.go
More file actions
44 lines (34 loc) · 1.07 KB
/
subject.go
File metadata and controls
44 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package dgnats
import (
"regexp"
"time"
"github.com/darwinOrg/go-common/utils"
)
const (
illegalRegexStr = "[.|*>]"
dash = "-"
)
var illegalRegex = regexp.MustCompile(illegalRegexStr)
type NatsSubject struct {
Category string `json:"category" binding:"required" remark:"流/topic"`
Name string `json:"name" binding:"required" remark:"tag"`
Group string `json:"group" remark:"队列"`
MaxAge time.Duration `json:"maxAge" remark:"最大时长"`
MaxAckPendingCount int `json:"maxAckPendingCount" remark:"未被确认的最多未发送消息数"`
}
func (s *NatsSubject) GetId() string {
id := s.Category + "-" + s.Name
if s.Group != "" {
id = id + "-" + s.Group
}
return ReplaceIllegalCharacter(id)
}
func (s *NatsSubject) GetDurable(tag string) string {
if s.Group != "" {
return s.GetId() + utils.IfReturn(tag != "", "-"+ReplaceIllegalCharacter(tag), "")
}
return ""
}
func ReplaceIllegalCharacter(str string) string {
return illegalRegex.ReplaceAllString(str, dash)
}