3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 11:59:40 +01:00

rename some getters

Rename getters in conformance with the "Effective Go" styleguide recommendation:
https://golang.org/doc/effective_go.html#Getters
This commit is contained in:
Shivaram Lingamneni 2017-11-03 02:36:55 -04:00
parent 94cf438f51
commit 9b74c47b74
8 changed files with 43 additions and 43 deletions

View File

@ -211,9 +211,9 @@ func (channel *Channel) nicks(target *Client) []string {
i = 0 i = 0
for i < length { for i < length {
if isUserhostInNames { if isUserhostInNames {
result[i] += clients[i].getNickMaskString() result[i] += clients[i].NickMaskString()
} else { } else {
result[i] += clients[i].getNick() result[i] += clients[i].Nick()
} }
i++ i++
} }
@ -644,7 +644,7 @@ func (channel *Channel) ShowMaskList(client *Client, mode Mode) {
rplendoflist = RPL_ENDOFINVITELIST rplendoflist = RPL_ENDOFINVITELIST
} }
nick := client.getNick() nick := client.Nick()
channel.stateMutex.RLock() channel.stateMutex.RLock()
// XXX don't acquire any new locks in this section, besides Socket.Write // XXX don't acquire any new locks in this section, besides Socket.Write
for mask := range channel.lists[mode].masks { for mask := range channel.lists[mode].masks {
@ -711,13 +711,13 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
return return
} }
kicklimit := client.server.getLimits().KickLen kicklimit := client.server.Limits().KickLen
if len(comment) > kicklimit { if len(comment) > kicklimit {
comment = comment[:kicklimit] comment = comment[:kicklimit]
} }
clientMask := client.getNickMaskString() clientMask := client.NickMaskString()
targetNick := target.getNick() targetNick := target.Nick()
for _, member := range channel.Members() { for _, member := range channel.Members() {
member.Send(nil, clientMask, "KICK", channel.name, targetNick, comment) member.Send(nil, clientMask, "KICK", channel.name, targetNick, comment)
} }
@ -739,7 +739,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
//TODO(dan): handle this more nicely, keep a list of last X invited channels on invitee rather than explicitly modifying the invite list? //TODO(dan): handle this more nicely, keep a list of last X invited channels on invitee rather than explicitly modifying the invite list?
if channel.flags[InviteOnly] { if channel.flags[InviteOnly] {
nmc := invitee.getNickCasefolded() nmc := invitee.NickCasefolded()
channel.stateMutex.Lock() channel.stateMutex.Lock()
channel.lists[InviteMask].Add(nmc) channel.lists[InviteMask].Add(nmc)
channel.stateMutex.Unlock() channel.stateMutex.Unlock()
@ -747,7 +747,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
for _, member := range channel.Members() { for _, member := range channel.Members() {
if member.capabilities.Has(caps.InviteNotify) && member != inviter && member != invitee && channel.ClientIsAtLeast(member, Halfop) { if member.capabilities.Has(caps.InviteNotify) && member != inviter && member != invitee && channel.ClientIsAtLeast(member, Halfop) {
member.Send(nil, inviter.getNickMaskString(), "INVITE", invitee.getNick(), channel.name) member.Send(nil, inviter.NickMaskString(), "INVITE", invitee.Nick(), channel.name)
} }
} }

View File

@ -52,7 +52,7 @@ func (cm *ChannelManager) Get(name string) *Channel {
func (cm *ChannelManager) Join(client *Client, name string, key string) error { func (cm *ChannelManager) Join(client *Client, name string, key string) error {
server := client.server server := client.server
casefoldedName, err := CasefoldChannel(name) casefoldedName, err := CasefoldChannel(name)
if err != nil || len(casefoldedName) > server.getLimits().ChannelLen { if err != nil || len(casefoldedName) > server.Limits().ChannelLen {
return NoSuchChannel return NoSuchChannel
} }

View File

@ -86,7 +86,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
go socket.RunSocketWriter() go socket.RunSocketWriter()
client := &Client{ client := &Client{
atime: now, atime: now,
authorized: server.getPassword() == nil, authorized: server.Password() == nil,
capabilities: caps.NewSet(), capabilities: caps.NewSet(),
capState: CapNone, capState: CapNone,
capVersion: caps.Cap301, capVersion: caps.Cap301,
@ -173,7 +173,7 @@ func (client *Client) recomputeMaxlens() (int, int) {
maxlenTags = 4096 maxlenTags = 4096
} }
if client.capabilities.Has(caps.MaxLine) { if client.capabilities.Has(caps.MaxLine) {
limits := client.server.getLimits() limits := client.server.Limits()
if limits.LineLen.Tags > maxlenTags { if limits.LineLen.Tags > maxlenTags {
maxlenTags = limits.LineLen.Tags maxlenTags = limits.LineLen.Tags
} }
@ -486,7 +486,7 @@ func (client *Client) LoggedIntoAccount() bool {
// RplISupport outputs our ISUPPORT lines to the client. This is used on connection and in VERSION responses. // RplISupport outputs our ISUPPORT lines to the client. This is used on connection and in VERSION responses.
func (client *Client) RplISupport() { func (client *Client) RplISupport() {
for _, tokenline := range client.server.getISupport().CachedReply { for _, tokenline := range client.server.ISupport().CachedReply {
// ugly trickery ahead // ugly trickery ahead
client.Send(nil, client.server.name, RPL_ISUPPORT, append([]string{client.nick}, tokenline...)...) client.Send(nil, client.server.name, RPL_ISUPPORT, append([]string{client.nick}, tokenline...)...)
} }
@ -679,7 +679,7 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
func (client *Client) Notice(text string) { func (client *Client) Notice(text string) {
limit := 400 limit := 400
if client.capabilities.Has(caps.MaxLine) { if client.capabilities.Has(caps.MaxLine) {
limit = client.server.getLimits().LineLen.Rest - 110 limit = client.server.Limits().LineLen.Rest - 110
} }
lines := wordWrap(text, limit) lines := wordWrap(text, limit)

View File

@ -5,19 +5,19 @@ package irc
import "github.com/oragono/oragono/irc/isupport" import "github.com/oragono/oragono/irc/isupport"
func (server *Server) getISupport() *isupport.List { func (server *Server) ISupport() *isupport.List {
server.configurableStateMutex.RLock() server.configurableStateMutex.RLock()
defer server.configurableStateMutex.RUnlock() defer server.configurableStateMutex.RUnlock()
return server.isupport return server.isupport
} }
func (server *Server) getLimits() Limits { func (server *Server) Limits() Limits {
server.configurableStateMutex.RLock() server.configurableStateMutex.RLock()
defer server.configurableStateMutex.RUnlock() defer server.configurableStateMutex.RUnlock()
return server.limits return server.limits
} }
func (server *Server) getPassword() []byte { func (server *Server) Password() []byte {
server.configurableStateMutex.RLock() server.configurableStateMutex.RLock()
defer server.configurableStateMutex.RUnlock() defer server.configurableStateMutex.RUnlock()
return server.password return server.password
@ -47,19 +47,19 @@ func (server *Server) DefaultChannelModes() Modes {
return server.defaultChannelModes return server.defaultChannelModes
} }
func (client *Client) getNick() string { func (client *Client) Nick() string {
client.stateMutex.RLock() client.stateMutex.RLock()
defer client.stateMutex.RUnlock() defer client.stateMutex.RUnlock()
return client.nick return client.nick
} }
func (client *Client) getNickMaskString() string { func (client *Client) NickMaskString() string {
client.stateMutex.RLock() client.stateMutex.RLock()
defer client.stateMutex.RUnlock() defer client.stateMutex.RUnlock()
return client.nickMaskString return client.nickMaskString
} }
func (client *Client) getNickCasefolded() string { func (client *Client) NickCasefolded() string {
client.stateMutex.RLock() client.stateMutex.RLock()
defer client.stateMutex.RUnlock() defer client.stateMutex.RUnlock()
return client.nickCasefolded return client.nickCasefolded

View File

@ -335,7 +335,7 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
return false return false
} }
targetNick := target.getNick() targetNick := target.Nick()
hasPrivs := client == target || msg.Command == "SAMODE" hasPrivs := client == target || msg.Command == "SAMODE"
if !hasPrivs { if !hasPrivs {
@ -513,9 +513,9 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
switch change.op { switch change.op {
case Add: case Add:
if channel.lists[change.mode].Length() >= client.server.getLimits().ChanListModes { if channel.lists[change.mode].Length() >= client.server.Limits().ChanListModes {
if !listFullWarned[change.mode] { if !listFullWarned[change.mode] {
client.Send(nil, client.server.name, ERR_BANLISTFULL, client.getNick(), channel.Name(), change.mode.String(), "Channel list is full") client.Send(nil, client.server.name, ERR_BANLISTFULL, client.Nick(), channel.Name(), change.mode.String(), "Channel list is full")
listFullWarned[change.mode] = true listFullWarned[change.mode] = true
} }
continue continue

View File

@ -37,8 +37,8 @@ var ErrMonitorLimitExceeded = errors.New("Monitor limit exceeded")
// AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line. // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
func (manager *MonitorManager) AlertAbout(client *Client, online bool) { func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
cfnick := client.getNickCasefolded() cfnick := client.NickCasefolded()
nick := client.getNick() nick := client.Nick()
var watchers []*Client var watchers []*Client
// safely copy the list of clients watching our nick // safely copy the list of clients watching our nick
manager.RLock() manager.RLock()
@ -53,7 +53,7 @@ func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
} }
for _, mClient := range watchers { for _, mClient := range watchers {
mClient.Send(nil, client.server.name, command, mClient.getNick(), nick) mClient.Send(nil, client.server.name, command, mClient.Nick(), nick)
} }
} }
@ -123,7 +123,7 @@ func monitorHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
handler, exists := metadataSubcommands[strings.ToLower(msg.Params[0])] handler, exists := metadataSubcommands[strings.ToLower(msg.Params[0])]
if !exists { if !exists {
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.getNick(), "MONITOR", msg.Params[0], "Unknown subcommand") client.Send(nil, server.name, ERR_UNKNOWNERROR, client.Nick(), "MONITOR", msg.Params[0], "Unknown subcommand")
return false return false
} }
@ -132,7 +132,7 @@ func monitorHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if len(msg.Params) < 2 { if len(msg.Params) < 2 {
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.getNick(), msg.Command, "Not enough parameters") client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.Nick(), msg.Command, "Not enough parameters")
return false return false
} }
@ -150,14 +150,14 @@ func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if len(msg.Params) < 2 { if len(msg.Params) < 2 {
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.getNick(), msg.Command, "Not enough parameters") client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.Nick(), msg.Command, "Not enough parameters")
return false return false
} }
var online []string var online []string
var offline []string var offline []string
limit := server.getLimits().MonitorEntries limit := server.Limits().MonitorEntries
targets := strings.Split(msg.Params[1], ",") targets := strings.Split(msg.Params[1], ",")
for _, target := range targets { for _, target := range targets {
@ -174,7 +174,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
err = server.monitorManager.Add(client, casefoldedTarget, limit) err = server.monitorManager.Add(client, casefoldedTarget, limit)
if err == ErrMonitorLimitExceeded { if err == ErrMonitorLimitExceeded {
client.Send(nil, server.name, ERR_MONLISTFULL, client.getNick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ",")) client.Send(nil, server.name, ERR_MONLISTFULL, client.Nick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
break break
} else if err != nil { } else if err != nil {
continue continue
@ -184,15 +184,15 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
if targetClient := server.clients.Get(casefoldedTarget); targetClient == nil { if targetClient := server.clients.Get(casefoldedTarget); targetClient == nil {
offline = append(offline, target) offline = append(offline, target)
} else { } else {
online = append(online, targetClient.getNick()) online = append(online, targetClient.Nick())
} }
} }
if len(online) > 0 { if len(online) > 0 {
client.Send(nil, server.name, RPL_MONONLINE, client.getNick(), strings.Join(online, ",")) client.Send(nil, server.name, RPL_MONONLINE, client.Nick(), strings.Join(online, ","))
} }
if len(offline) > 0 { if len(offline) > 0 {
client.Send(nil, server.name, RPL_MONOFFLINE, client.getNick(), strings.Join(offline, ",")) client.Send(nil, server.name, RPL_MONOFFLINE, client.Nick(), strings.Join(offline, ","))
} }
return false return false
@ -211,13 +211,13 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
replynick := cfnick replynick := cfnick
// report the uncasefolded nick if it's available, i.e., the client is online // report the uncasefolded nick if it's available, i.e., the client is online
if mclient := server.clients.Get(cfnick); mclient != nil { if mclient := server.clients.Get(cfnick); mclient != nil {
replynick = mclient.getNick() replynick = mclient.Nick()
} }
nickList = append(nickList, replynick) nickList = append(nickList, replynick)
} }
for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") { for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") {
client.Send(nil, server.name, RPL_MONLIST, client.getNick(), line) client.Send(nil, server.name, RPL_MONLIST, client.Nick(), line)
} }
client.Send(nil, server.name, RPL_ENDOFMONLIST, "End of MONITOR list") client.Send(nil, server.name, RPL_ENDOFMONLIST, "End of MONITOR list")
@ -236,18 +236,18 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
if target == nil { if target == nil {
offline = append(offline, name) offline = append(offline, name)
} else { } else {
online = append(online, target.getNick()) online = append(online, target.Nick())
} }
} }
if len(online) > 0 { if len(online) > 0 {
for _, line := range utils.ArgsToStrings(maxLastArgLength, online, ",") { for _, line := range utils.ArgsToStrings(maxLastArgLength, online, ",") {
client.Send(nil, server.name, RPL_MONONLINE, client.getNick(), line) client.Send(nil, server.name, RPL_MONONLINE, client.Nick(), line)
} }
} }
if len(offline) > 0 { if len(offline) > 0 {
for _, line := range utils.ArgsToStrings(maxLastArgLength, offline, ",") { for _, line := range utils.ArgsToStrings(maxLastArgLength, offline, ",") {
client.Send(nil, server.name, RPL_MONOFFLINE, client.getNick(), line) client.Send(nil, server.name, RPL_MONOFFLINE, client.Nick(), line)
} }
} }

View File

@ -34,7 +34,7 @@ func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
return false return false
} }
if err != nil || len(nicknameRaw) > server.getLimits().NickLen || restrictedNicknames[nickname] { if err != nil || len(nicknameRaw) > server.Limits().NickLen || restrictedNicknames[nickname] {
client.Send(nil, server.name, ERR_ERRONEUSNICKNAME, client.nick, nicknameRaw, "Erroneous nickname") client.Send(nil, server.name, ERR_ERRONEUSNICKNAME, client.nick, nicknameRaw, "Erroneous nickname")
return false return false
} }

View File

@ -577,7 +577,7 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) (resul
default: default:
code = ERR_UNKNOWNERROR code = ERR_UNKNOWNERROR
} }
client.Send(nil, server.name, code, client.getNick(), "RENAME", name, err.Error()) client.Send(nil, server.name, code, client.Nick(), "RENAME", name, err.Error())
} }
oldName := strings.TrimSpace(msg.Params[0]) oldName := strings.TrimSpace(msg.Params[0])
@ -697,7 +697,7 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
} }
err := server.channels.Join(client, name, key) err := server.channels.Join(client, name, key)
if err == NoSuchChannel { if err == NoSuchChannel {
client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.getNick(), name, "No such channel") client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), name, "No such channel")
} }
} }
return false return false
@ -1044,7 +1044,7 @@ func (target *Client) rplWhoReply(channel *Channel, client *Client) {
flags += channel.ClientPrefixes(client, target.capabilities.Has(caps.MultiPrefix)) flags += channel.ClientPrefixes(client, target.capabilities.Has(caps.MultiPrefix))
channelName = channel.name channelName = channel.name
} }
target.Send(nil, target.server.name, RPL_WHOREPLY, target.nick, channelName, client.Username(), client.Hostname(), client.server.name, client.getNick(), flags, strconv.Itoa(client.hops)+" "+client.Realname()) target.Send(nil, target.server.name, RPL_WHOREPLY, target.nick, channelName, client.Username(), client.Hostname(), client.server.name, client.Nick(), flags, strconv.Itoa(client.hops)+" "+client.Realname())
} }
func whoChannel(client *Client, channel *Channel, friends ClientSet) { func whoChannel(client *Client, channel *Channel, friends ClientSet) {
@ -1586,7 +1586,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if len(msg.Params) > 0 { if len(msg.Params) > 0 {
isAway = true isAway = true
text = msg.Params[0] text = msg.Params[0]
awayLen := server.getLimits().AwayLen awayLen := server.Limits().AwayLen
if len(text) > awayLen { if len(text) > awayLen {
text = text[:awayLen] text = text[:awayLen]
} }