Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <rip@devco.net>
  • Loading branch information
ripienaar committed Jun 29, 2021
1 parent 559051c commit 7d68c97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ func Compression(enabled bool) Option {
// CustomInboxPrefix configures the request + reply inbox prefix
func CustomInboxPrefix(p string) Option {
return func(o *Options) error {
if p == "" || strings.HasSuffix(p, ">") || strings.HasSuffix(p, "*") || strings.HasSuffix(p, ".") || strings.HasPrefix(p, ">") || strings.HasPrefix(p, "*") {
if p == "" || strings.Contains(p, ">") || strings.Contains(p, "*") || strings.HasSuffix(p, ".") {
return fmt.Errorf("nats: invald custom prefix")
}
o.InboxPrefix = p
Expand Down Expand Up @@ -3359,7 +3359,7 @@ func (nc *Conn) createNewRequestAndSend(subj string, hdr, data []byte) (chan *Ms
// Create new literal Inbox and map to a chan msg.
mch := make(chan *Msg, RequestChanLen)
respInbox := nc.newRespInbox()
token := respInbox[nc.respSubLen+1:]
token := respInbox[nc.respSubLen:]

nc.respMap[token] = mch
if nc.respMux == nil {
Expand Down Expand Up @@ -3487,12 +3487,10 @@ func (nc *Conn) oldRequest(subj string, hdr, data []byte, timeout time.Duration)

// InboxPrefix is the prefix for all inbox subjects.
const (
InboxPrefix = "_INBOX."
inboxPrefixLen = len(InboxPrefix)
respInboxPrefixLen = inboxPrefixLen + nuidSize + 1
replySuffixLen = 8 // Gives us 62^8
rdigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
base = 62
InboxPrefix = "_INBOX."
inboxPrefixLen = len(InboxPrefix)
rdigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
base = 62
)

// NewInbox will return an inbox string which can be used for directed replies from
Expand Down Expand Up @@ -3522,7 +3520,7 @@ func (nc *Conn) newInbox() string {
// Function to init new response structures.
func (nc *Conn) initNewResp() {
nc.respSubPrefix = fmt.Sprintf("%s.", nc.newInbox())
nc.respSubLen = len(nc.respSubPrefix) - 1
nc.respSubLen = len(nc.respSubPrefix)
nc.respSub = fmt.Sprintf("%s*", nc.respSubPrefix)
nc.respMap = make(map[string]chan *Msg)
nc.respRand = rand.New(rand.NewSource(time.Now().UnixNano()))
Expand Down
2 changes: 1 addition & 1 deletion nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,7 @@ func TestMsg_RespondMsg(t *testing.T) {

func TestCustomInboxPrefix(t *testing.T) {
opts := &Options{}
for _, p := range []string{"$BOB.", "$BOB.*", "$BOB.>", ">", ".", ""} {
for _, p := range []string{"$BOB.", "$BOB.*", "$BOB.>", ">", ".", "", "BOB.*.X", "BOB.>.X"} {
err := CustomInboxPrefix(p)(opts)
if err == nil {
t.Fatalf("Expeted error for %q", p)
Expand Down

0 comments on commit 7d68c97

Please sign in to comment.