Skip to content

Commit

Permalink
Merge pull request #47 from muzzammilshahid/fix-unregister-unsubscribe
Browse files Browse the repository at this point in the history
Correct names of 'Unregister' and 'Unsubscribe' messages
  • Loading branch information
muzzammilshahid authored Jul 6, 2024
2 parents c09b611 + 2e8e832 commit 7b25d7d
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 111 deletions.
6 changes: 3 additions & 3 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func (b *Broker) ReceiveMessage(sessionID int64, msg messages.Message) (*Message
subscribed := messages.NewSubscribed(subscribe.RequestID(), subscription.ID)
result := &MessageWithRecipient{Message: subscribed, Recipient: sessionID}
return result, nil
case messages.MessageTypeUnSubscribe:
unsubscribe := msg.(*messages.UnSubscribe)
case messages.MessageTypeUnsubscribe:
unsubscribe := msg.(*messages.Unsubscribe)
subscriptions, exists := b.subscriptionsBySession[sessionID]
if !exists {
return nil, fmt.Errorf("broker: cannot unsubscribe, session %d doesn't exist", sessionID)
Expand All @@ -126,7 +126,7 @@ func (b *Broker) ReceiveMessage(sessionID int64, msg messages.Message) (*Message

delete(b.subscriptionsBySession[sessionID], subscription.ID)

unsubscribed := messages.NewUnSubscribed(unsubscribe.RequestID())
unsubscribed := messages.NewUnsubscribed(unsubscribe.RequestID())
result := &MessageWithRecipient{Message: unsubscribed, Recipient: sessionID}
return result, nil
case messages.MessageTypeError:
Expand Down
6 changes: 3 additions & 3 deletions dealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func (d *Dealer) ReceiveMessage(sessionID int64, msg messages.Message) (*Message

registered := messages.NewRegistered(register.RequestID(), registration.ID)
return &MessageWithRecipient{Message: registered, Recipient: sessionID}, nil
case messages.MessageTypeUnRegister:
unregister := msg.(*messages.UnRegister)
case messages.MessageTypeUnregister:
unregister := msg.(*messages.Unregister)
registrations, exists := d.registrationsBySession[sessionID]
if !exists || len(registrations) == 0 {
return nil, fmt.Errorf("unregister: session %d has no registration %d", sessionID,
Expand All @@ -183,7 +183,7 @@ func (d *Dealer) ReceiveMessage(sessionID int64, msg messages.Message) (*Message
delete(d.registrationsByProcedure, registration.Procedure)
}

unregistered := messages.NewUnRegistered(unregister.RequestID())
unregistered := messages.NewUnregistered(unregister.RequestID())
return &MessageWithRecipient{Message: unregistered, Recipient: sessionID}, nil
case messages.MessageTypeError:
wErr := msg.(*messages.Error)
Expand Down
2 changes: 1 addition & 1 deletion dealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDealerAddRemoveSession(t *testing.T) {
})
}

func TestDealerRegisterUnRegister(t *testing.T) {
func TestDealerRegisterUnregister(t *testing.T) {
dealer := wampproto.NewDealer()

t.Run("Register", func(t *testing.T) {
Expand Down
44 changes: 22 additions & 22 deletions messages/unregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@ package messages

import "fmt"

const MessageTypeUnRegister = 66
const MessageNameUnRegister = "UNREGISTER"
const MessageTypeUnregister = 66
const MessageNameUnregister = "UNREGISTER"

var unRegisterValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
var unregisterValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
MinLength: 3,
MaxLength: 3,
Message: MessageNameUnRegister,
Message: MessageNameUnregister,
Spec: Spec{
1: ValidateRequestID,
2: ValidateRegistrationID,
},
}

type UnRegisterFields interface {
type UnregisterFields interface {
RequestID() int64
RegistrationID() int64
}

type unRegisterFields struct {
type unregisterFields struct {
requestID int64
registrationID int64
}

func (ur *unRegisterFields) RequestID() int64 {
func (ur *unregisterFields) RequestID() int64 {
return ur.requestID
}

func (ur *unRegisterFields) RegistrationID() int64 {
func (ur *unregisterFields) RegistrationID() int64 {
return ur.registrationID
}

type UnRegister struct {
UnRegisterFields
type Unregister struct {
UnregisterFields
}

func NewUnRegister(requestID, registrationID int64) *UnRegister {
return &UnRegister{UnRegisterFields: &unRegisterFields{requestID: requestID, registrationID: registrationID}}
func NewUnregister(requestID, registrationID int64) *Unregister {
return &Unregister{UnregisterFields: &unregisterFields{requestID: requestID, registrationID: registrationID}}
}

func NewUnRegisterWithFields(fields UnRegisterFields) *UnRegister {
return &UnRegister{UnRegisterFields: fields}
func NewUnregisterWithFields(fields UnregisterFields) *Unregister {
return &Unregister{UnregisterFields: fields}
}

func (ur *UnRegister) Type() int {
return MessageTypeUnRegister
func (ur *Unregister) Type() int {
return MessageTypeUnregister
}

func (ur *UnRegister) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unRegisterValidationSpec)
func (ur *Unregister) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unregisterValidationSpec)
if err != nil {
return fmt.Errorf("unregister: failed to validate message %s: %w", MessageNameUnRegister, err)
return fmt.Errorf("unregister: failed to validate message %s: %w", MessageNameUnregister, err)
}

ur.UnRegisterFields = &unRegisterFields{requestID: fields.RequestID, registrationID: fields.RegistrationID}
ur.UnregisterFields = &unregisterFields{requestID: fields.RequestID, registrationID: fields.RegistrationID}

return nil
}

func (ur *UnRegister) Marshal() []any {
return []any{MessageTypeUnRegister, ur.RequestID(), ur.RegistrationID()}
func (ur *Unregister) Marshal() []any {
return []any{MessageTypeUnregister, ur.RequestID(), ur.RegistrationID()}
}
42 changes: 21 additions & 21 deletions messages/unregistered.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,57 @@ package messages

import "fmt"

const MessageTypeUnRegistered = 67
const MessageNameUnRegistered = "UNREGISTERED"
const MessageTypeUnregistered = 67
const MessageNameUnregistered = "UNREGISTERED"

var unRegisteredValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
var unregisteredValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
MinLength: 2,
MaxLength: 2,
Message: MessageNameUnRegistered,
Message: MessageNameUnregistered,
Spec: Spec{
1: ValidateRequestID,
},
}

type UnRegisteredFields interface {
type UnregisteredFields interface {
RequestID() int64
}

type unRegisteredFields struct {
type unregisteredFields struct {
requestID int64
}

func (ur *unRegisteredFields) RequestID() int64 {
func (ur *unregisteredFields) RequestID() int64 {
return ur.requestID
}

type UnRegistered struct {
UnRegisteredFields
type Unregistered struct {
UnregisteredFields
}

func NewUnRegistered(requestID int64) *UnRegistered {
return &UnRegistered{UnRegisteredFields: &unRegisteredFields{requestID: requestID}}
func NewUnregistered(requestID int64) *Unregistered {
return &Unregistered{UnregisteredFields: &unregisteredFields{requestID: requestID}}
}

func NewUnRegisteredWithFields(fields UnRegisteredFields) *UnRegistered {
return &UnRegistered{UnRegisteredFields: fields}
func NewUnregisteredWithFields(fields UnregisteredFields) *Unregistered {
return &Unregistered{UnregisteredFields: fields}
}

func (ur *UnRegistered) Type() int {
return MessageTypeUnRegistered
func (ur *Unregistered) Type() int {
return MessageTypeUnregistered
}

func (ur *UnRegistered) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unRegisteredValidationSpec)
func (ur *Unregistered) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unregisteredValidationSpec)
if err != nil {
return fmt.Errorf("unregistered: failed to validate message %s: %w", MessageNameUnRegistered, err)
return fmt.Errorf("unregistered: failed to validate message %s: %w", MessageNameUnregistered, err)
}

ur.UnRegisteredFields = &unRegisteredFields{requestID: fields.RequestID}
ur.UnregisteredFields = &unregisteredFields{requestID: fields.RequestID}

return nil
}

func (ur *UnRegistered) Marshal() []any {
return []any{MessageTypeUnRegistered, ur.RequestID()}
func (ur *Unregistered) Marshal() []any {
return []any{MessageTypeUnregistered, ur.RequestID()}
}
44 changes: 22 additions & 22 deletions messages/unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@ package messages

import "fmt"

const MessageTypeUnSubscribe = 34
const MessageNameUnSubscribe = "UNSUBSCRIBE"
const MessageTypeUnsubscribe = 34
const MessageNameUnsubscribe = "UNSUBSCRIBE"

var unSubscribeValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
var unsubscribeValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
MinLength: 3,
MaxLength: 3,
Message: MessageNameUnSubscribe,
Message: MessageNameUnsubscribe,
Spec: Spec{
1: ValidateRequestID,
2: ValidateSubscriptionID,
},
}

type UnSubscribeFields interface {
type UnsubscribeFields interface {
RequestID() int64
SubscriptionID() int64
}

type unSubscribeFields struct {
type unsubscribeFields struct {
requestID int64
subscriptionID int64
}

func (us *unSubscribeFields) RequestID() int64 {
func (us *unsubscribeFields) RequestID() int64 {
return us.requestID
}

func (us *unSubscribeFields) SubscriptionID() int64 {
func (us *unsubscribeFields) SubscriptionID() int64 {
return us.subscriptionID
}

type UnSubscribe struct {
UnSubscribeFields
type Unsubscribe struct {
UnsubscribeFields
}

func NewUnSubscribe(requestID, subscriptionID int64) *UnSubscribe {
return &UnSubscribe{UnSubscribeFields: &unSubscribeFields{requestID: requestID, subscriptionID: subscriptionID}}
func NewUnsubscribe(requestID, subscriptionID int64) *Unsubscribe {
return &Unsubscribe{UnsubscribeFields: &unsubscribeFields{requestID: requestID, subscriptionID: subscriptionID}}
}

func NewUnSubscribeWithFields(fields UnSubscribeFields) *UnSubscribe {
return &UnSubscribe{UnSubscribeFields: fields}
func NewUnsubscribeWithFields(fields UnsubscribeFields) *Unsubscribe {
return &Unsubscribe{UnsubscribeFields: fields}
}

func (us *UnSubscribe) Type() int {
return MessageTypeUnSubscribe
func (us *Unsubscribe) Type() int {
return MessageTypeUnsubscribe
}

func (us *UnSubscribe) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unSubscribeValidationSpec)
func (us *Unsubscribe) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unsubscribeValidationSpec)
if err != nil {
return fmt.Errorf("unregister: failed to validate message %s: %w", MessageNameUnSubscribe, err)
return fmt.Errorf("unregister: failed to validate message %s: %w", MessageNameUnsubscribe, err)
}

us.UnSubscribeFields = &unSubscribeFields{requestID: fields.RequestID, subscriptionID: fields.SubscriptionID}
us.UnsubscribeFields = &unsubscribeFields{requestID: fields.RequestID, subscriptionID: fields.SubscriptionID}

return nil
}

func (us *UnSubscribe) Marshal() []any {
return []any{MessageTypeUnSubscribe, us.RequestID(), us.SubscriptionID()}
func (us *Unsubscribe) Marshal() []any {
return []any{MessageTypeUnsubscribe, us.RequestID(), us.SubscriptionID()}
}
42 changes: 21 additions & 21 deletions messages/unsubscribed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,57 @@ package messages

import "fmt"

const MessageTypeUnSubscribed = 35
const MessageNameUnSubscribed = "UNSUBSCRIBED"
const MessageTypeUnsubscribed = 35
const MessageNameUnsubscribed = "UNSUBSCRIBED"

var unSubscribedValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
var unsubscribedValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
MinLength: 2,
MaxLength: 2,
Message: MessageNameUnSubscribed,
Message: MessageNameUnsubscribed,
Spec: Spec{
1: ValidateRequestID,
},
}

type UnSubscribedFields interface {
type UnsubscribedFields interface {
RequestID() int64
}

type unSubscribedFields struct {
type unsubscribedFields struct {
requestID int64
}

func (us *unSubscribedFields) RequestID() int64 {
func (us *unsubscribedFields) RequestID() int64 {
return us.requestID
}

type UnSubscribed struct {
UnSubscribedFields
type Unsubscribed struct {
UnsubscribedFields
}

func NewUnSubscribed(requestID int64) *UnSubscribed {
return &UnSubscribed{UnSubscribedFields: &unSubscribedFields{requestID: requestID}}
func NewUnsubscribed(requestID int64) *Unsubscribed {
return &Unsubscribed{UnsubscribedFields: &unsubscribedFields{requestID: requestID}}
}

func NewUnSubscribedWithFields(fields UnSubscribedFields) *UnSubscribed {
return &UnSubscribed{UnSubscribedFields: fields}
func NewUnsubscribedWithFields(fields UnsubscribedFields) *Unsubscribed {
return &Unsubscribed{UnsubscribedFields: fields}
}

func (us *UnSubscribed) Type() int {
return MessageTypeUnSubscribed
func (us *Unsubscribed) Type() int {
return MessageTypeUnsubscribed
}

func (us *UnSubscribed) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unSubscribedValidationSpec)
func (us *Unsubscribed) Parse(wampMsg []any) error {
fields, err := ValidateMessage(wampMsg, unsubscribedValidationSpec)
if err != nil {
return fmt.Errorf("unsubscribed: failed to validate message %s: %w", MessageNameUnSubscribed, err)
return fmt.Errorf("unsubscribed: failed to validate message %s: %w", MessageNameUnsubscribed, err)
}

us.UnSubscribedFields = &unSubscribedFields{requestID: fields.RequestID}
us.UnsubscribedFields = &unsubscribedFields{requestID: fields.RequestID}

return nil
}

func (us *UnSubscribed) Marshal() []any {
return []any{MessageTypeUnSubscribed, us.RequestID()}
func (us *Unsubscribed) Marshal() []any {
return []any{MessageTypeUnsubscribed, us.RequestID()}
}
Loading

0 comments on commit 7b25d7d

Please sign in to comment.