refactor: add irc.MessageType custom type with Name() and String() methods
All checks were successful
check / check (push) Successful in 2m28s
All checks were successful
check / check (push) Successful in 2m28s
- Create 'type MessageType int' in pkg/irc/numerics.go - Type all Rpl*/Err* numeric constants as MessageType - Add Name() method returning the standard IRC name (e.g. RPL_WELCOME) - Add String() method returning zero-padded numeric (e.g. 001) - Update enqueueNumeric/respondIRCError to accept MessageType - Update internal/db to use MessageType conversion for Name() calls - Change names map key type from int to MessageType Refs #52
This commit is contained in:
@@ -746,7 +746,7 @@ func scanMessages(
|
||||
code, _ := strconv.Atoi(msg.Command)
|
||||
msg.Code = code
|
||||
|
||||
if name := irc.Name(code); name != "" {
|
||||
if name := irc.Name(irc.MessageType(code)); name != "" {
|
||||
msg.Command = name
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,12 +398,12 @@ func (hdlr *Handlers) serverName() string {
|
||||
func (hdlr *Handlers) enqueueNumeric(
|
||||
ctx context.Context,
|
||||
clientID int64,
|
||||
code int,
|
||||
code irc.MessageType,
|
||||
nick string,
|
||||
params []string,
|
||||
text string,
|
||||
) {
|
||||
command := fmt.Sprintf("%03d", code)
|
||||
command := code.String()
|
||||
|
||||
body, err := json.Marshal([]string{text})
|
||||
if err != nil {
|
||||
@@ -969,7 +969,7 @@ func (hdlr *Handlers) respondIRCError(
|
||||
writer http.ResponseWriter,
|
||||
request *http.Request,
|
||||
clientID, sessionID int64,
|
||||
code int,
|
||||
code irc.MessageType,
|
||||
nick string,
|
||||
params []string,
|
||||
text string,
|
||||
|
||||
Reference in New Issue
Block a user