Skip to content

Commit 4dc03fc

Browse files
committed
chore(pr): address pr comments
1 parent c7ffeff commit 4dc03fc

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

internal/pool/conn.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ func (cn *Conn) SetNetConn(netConn net.Conn) {
7474
cn.bw.Reset(netConn)
7575
}
7676

77-
func (cn *Conn) GetNetConn() net.Conn {
78-
return cn.netConn
79-
}
80-
8177
func (cn *Conn) Write(b []byte) (int, error) {
8278
return cn.netConn.Write(b)
8379
}
@@ -97,7 +93,6 @@ func (cn *Conn) WithReader(
9793
return err
9894
}
9995
}
100-
10196
return fn(cn.rd)
10297
}
10398

push/errors.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ const (
1919
ReasonPushNotificationsDisabled = "push notifications are disabled"
2020
)
2121

22+
// ProcessorType represents the type of processor involved in the error
23+
// defined as a custom type for better readability and easier maintenance
24+
type ProcessorType string
25+
26+
const (
27+
// ProcessorTypes
28+
ProcessorTypeProcessor = ProcessorType("processor")
29+
ProcessorTypeVoidProcessor = ProcessorType("void_processor")
30+
ProcessorTypeCustom = ProcessorType("custom")
31+
)
32+
33+
// ProcessorOperation represents the operation being performed by the processor
34+
// defined as a custom type for better readability and easier maintenance
35+
type ProcessorOperation string
36+
37+
const (
38+
// ProcessorOperations
39+
ProcessorOperationProcess = ProcessorOperation("process")
40+
ProcessorOperationRegister = ProcessorOperation("register")
41+
ProcessorOperationUnregister = ProcessorOperation("unregister")
42+
ProcessorOperationUnknown = ProcessorOperation("unknown")
43+
)
44+
2245
// Common error variables for reuse
2346
var (
2447
// ErrHandlerNil is returned when attempting to register a nil handler
@@ -29,31 +52,31 @@ var (
2952

3053
// ErrHandlerExists creates an error for when attempting to overwrite an existing handler
3154
func ErrHandlerExists(pushNotificationName string) error {
32-
return NewHandlerError("register", pushNotificationName, ReasonHandlerExists, nil)
55+
return NewHandlerError(ProcessorOperationRegister, pushNotificationName, ReasonHandlerExists, nil)
3356
}
3457

3558
// ErrProtectedHandler creates an error for when attempting to unregister a protected handler
3659
func ErrProtectedHandler(pushNotificationName string) error {
37-
return NewHandlerError("unregister", pushNotificationName, ReasonHandlerProtected, nil)
60+
return NewHandlerError(ProcessorOperationUnregister, pushNotificationName, ReasonHandlerProtected, nil)
3861
}
3962

4063
// VoidProcessor errors
4164

4265
// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
4366
func ErrVoidProcessorRegister(pushNotificationName string) error {
44-
return NewProcessorError("void_processor", "register", pushNotificationName, ReasonPushNotificationsDisabled, nil)
67+
return NewProcessorError(ProcessorTypeVoidProcessor, ProcessorOperationRegister, pushNotificationName, ReasonPushNotificationsDisabled, nil)
4568
}
4669

4770
// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
4871
func ErrVoidProcessorUnregister(pushNotificationName string) error {
49-
return NewProcessorError("void_processor", "unregister", pushNotificationName, ReasonPushNotificationsDisabled, nil)
72+
return NewProcessorError(ProcessorTypeVoidProcessor, ProcessorOperationUnregister, pushNotificationName, ReasonPushNotificationsDisabled, nil)
5073
}
5174

5275
// Error type definitions for advanced error handling
5376

5477
// HandlerError represents errors related to handler operations
5578
type HandlerError struct {
56-
Operation string // "register", "unregister", "get"
79+
Operation ProcessorOperation
5780
PushNotificationName string
5881
Reason string
5982
Err error
@@ -71,7 +94,7 @@ func (e *HandlerError) Unwrap() error {
7194
}
7295

7396
// NewHandlerError creates a new HandlerError
74-
func NewHandlerError(operation, pushNotificationName, reason string, err error) *HandlerError {
97+
func NewHandlerError(operation ProcessorOperation, pushNotificationName, reason string, err error) *HandlerError {
7598
return &HandlerError{
7699
Operation: operation,
77100
PushNotificationName: pushNotificationName,
@@ -82,9 +105,9 @@ func NewHandlerError(operation, pushNotificationName, reason string, err error)
82105

83106
// ProcessorError represents errors related to processor operations
84107
type ProcessorError struct {
85-
ProcessorType string // "processor", "void_processor"
86-
Operation string // "process", "register", "unregister"
87-
PushNotificationName string // Name of the push notification involved
108+
ProcessorType ProcessorType // "processor", "void_processor"
109+
Operation ProcessorOperation // "process", "register", "unregister"
110+
PushNotificationName string // Name of the push notification involved
88111
Reason string
89112
Err error
90113
}
@@ -105,7 +128,7 @@ func (e *ProcessorError) Unwrap() error {
105128
}
106129

107130
// NewProcessorError creates a new ProcessorError
108-
func NewProcessorError(processorType, operation, pushNotificationName, reason string, err error) *ProcessorError {
131+
func NewProcessorError(processorType ProcessorType, operation ProcessorOperation, pushNotificationName, reason string, err error) *ProcessorError {
109132
return &ProcessorError{
110133
ProcessorType: processorType,
111134
Operation: operation,
@@ -125,23 +148,23 @@ func IsHandlerNilError(err error) bool {
125148
// IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler
126149
func IsHandlerExistsError(err error) bool {
127150
if handlerErr, ok := err.(*HandlerError); ok {
128-
return handlerErr.Operation == "register" && handlerErr.Reason == ReasonHandlerExists
151+
return handlerErr.Operation == ProcessorOperationRegister && handlerErr.Reason == ReasonHandlerExists
129152
}
130153
return false
131154
}
132155

133156
// IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler
134157
func IsProtectedHandlerError(err error) bool {
135158
if handlerErr, ok := err.(*HandlerError); ok {
136-
return handlerErr.Operation == "unregister" && handlerErr.Reason == ReasonHandlerProtected
159+
return handlerErr.Operation == ProcessorOperationUnregister && handlerErr.Reason == ReasonHandlerProtected
137160
}
138161
return false
139162
}
140163

141164
// IsVoidProcessorError checks if an error is due to void processor operations
142165
func IsVoidProcessorError(err error) bool {
143166
if procErr, ok := err.(*ProcessorError); ok {
144-
return procErr.ProcessorType == "void_processor" && procErr.Reason == ReasonPushNotificationsDisabled
167+
return procErr.ProcessorType == ProcessorTypeVoidProcessor && procErr.Reason == ReasonPushNotificationsDisabled
145168
}
146169
return false
147170
}

0 commit comments

Comments
 (0)