refactor: replace all bare command string literals with named constants
All checks were successful
check / check (push) Successful in 2m15s

Extract cmdLusers, cmdMode, cmdMotd, cmdNames, cmdNotice, cmdPing, cmdPong
constants in internal/handlers/api.go. Add corresponding constants in
cmd/neoirc-cli/main.go and cmd/neoirc-cli/api/client.go. Replace every bare
IRC command string literal in switch cases and command dispatch code with the
named constant. Zero bare command strings remain in any dispatch path.
This commit is contained in:
2026-03-09 15:23:00 -07:00
parent a193831ed4
commit 5efb4b6949
3 changed files with 49 additions and 28 deletions

View File

@@ -29,8 +29,15 @@ const (
maxHistLimit = 500
cmdJoin = "JOIN"
cmdList = "LIST"
cmdLusers = "LUSERS"
cmdMode = "MODE"
cmdMotd = "MOTD"
cmdNames = "NAMES"
cmdNick = "NICK"
cmdNotice = "NOTICE"
cmdPart = "PART"
cmdPing = "PING"
cmdPong = "PONG"
cmdPrivmsg = "PRIVMSG"
cmdQuit = "QUIT"
cmdTopic = "TOPIC"
@@ -758,7 +765,7 @@ func (hdlr *Handlers) dispatchCommand(
bodyLines func() []string,
) {
switch command {
case cmdPrivmsg, "NOTICE":
case cmdPrivmsg, cmdNotice:
hdlr.handlePrivmsg(
writer, request,
sessionID, clientID, nick,
@@ -789,7 +796,7 @@ func (hdlr *Handlers) dispatchCommand(
hdlr.handleQuit(
writer, request, sessionID, nick, body,
)
case "MOTD", cmdList, cmdWho, cmdWhois, "PING":
case cmdMotd, cmdList, cmdWho, cmdWhois, cmdPing:
hdlr.dispatchInfoCommand(
writer, request,
sessionID, clientID, nick,
@@ -812,13 +819,13 @@ func (hdlr *Handlers) dispatchQueryCommand(
bodyLines func() []string,
) {
switch command {
case "MODE":
case cmdMode:
hdlr.handleMode(
writer, request,
sessionID, clientID, nick,
target, bodyLines,
)
case "NAMES":
case cmdNames:
hdlr.handleNames(
writer, request,
sessionID, clientID, nick, target,
@@ -839,7 +846,7 @@ func (hdlr *Handlers) dispatchQueryCommand(
writer, request,
sessionID, clientID, nick, target,
)
case "LUSERS":
case cmdLusers:
hdlr.handleLusers(
writer, request,
sessionID, clientID, nick,
@@ -1571,7 +1578,7 @@ func (hdlr *Handlers) dispatchInfoCommand(
okResp := map[string]string{"status": "ok"}
switch command {
case "MOTD":
case cmdMotd:
hdlr.deliverMOTD(
request, clientID, sessionID, nick,
)
@@ -1589,10 +1596,10 @@ func (hdlr *Handlers) dispatchInfoCommand(
request, clientID, sessionID, nick,
target, bodyLines,
)
case "PING":
case cmdPing:
hdlr.respondJSON(writer, request,
map[string]string{
"command": "PONG",
"command": cmdPong,
"from": hdlr.serverName(),
},
http.StatusOK)
@@ -1892,7 +1899,7 @@ func (hdlr *Handlers) handleMode(
if target == "" {
hdlr.respondIRCError(
writer, request, clientID, sessionID,
"461", nick, []string{"MODE"},
"461", nick, []string{cmdMode},
"Not enough parameters",
)
@@ -1981,7 +1988,7 @@ func (hdlr *Handlers) handleNames(
if target == "" {
hdlr.respondIRCError(
writer, request, clientID, sessionID,
"461", nick, []string{"NAMES"},
"461", nick, []string{cmdNames},
"Not enough parameters",
)