3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 03:49:27 +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
for i < length {
if isUserhostInNames {
result[i] += clients[i].getNickMaskString()
result[i] += clients[i].NickMaskString()
} else {
result[i] += clients[i].getNick()
result[i] += clients[i].Nick()
}
i++
}
@ -644,7 +644,7 @@ func (channel *Channel) ShowMaskList(client *Client, mode Mode) {
rplendoflist = RPL_ENDOFINVITELIST
}
nick := client.getNick()
nick := client.Nick()
channel.stateMutex.RLock()
// XXX don't acquire any new locks in this section, besides Socket.Write
for mask := range channel.lists[mode].masks {
@ -711,13 +711,13 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
return
}
kicklimit := client.server.getLimits().KickLen
kicklimit := client.server.Limits().KickLen
if len(comment) > kicklimit {
comment = comment[:kicklimit]
}
clientMask := client.getNickMaskString()
targetNick := target.getNick()
clientMask := client.NickMaskString()
targetNick := target.Nick()
for _, member := range channel.Members() {
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?
if channel.flags[InviteOnly] {
nmc := invitee.getNickCasefolded()
nmc := invitee.NickCasefolded()
channel.stateMutex.Lock()
channel.lists[InviteMask].Add(nmc)
channel.stateMutex.Unlock()
@ -747,7 +747,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
for _, member := range channel.Members() {
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 {
server := client.server
casefoldedName, err := CasefoldChannel(name)
if err != nil || len(casefoldedName) > server.getLimits().ChannelLen {
if err != nil || len(casefoldedName) > server.Limits().ChannelLen {
return NoSuchChannel
}

View File

@ -86,7 +86,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
go socket.RunSocketWriter()
client := &Client{
atime: now,
authorized: server.getPassword() == nil,
authorized: server.Password() == nil,
capabilities: caps.NewSet(),
capState: CapNone,
capVersion: caps.Cap301,
@ -173,7 +173,7 @@ func (client *Client) recomputeMaxlens() (int, int) {
maxlenTags = 4096
}
if client.capabilities.Has(caps.MaxLine) {
limits := client.server.getLimits()
limits := client.server.Limits()
if limits.LineLen.Tags > maxlenTags {
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.
func (client *Client) RplISupport() {
for _, tokenline := range client.server.getISupport().CachedReply {
for _, tokenline := range client.server.ISupport().CachedReply {
// ugly trickery ahead
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) {
limit := 400
if client.capabilities.Has(caps.MaxLine) {
limit = client.server.getLimits().LineLen.Rest - 110
limit = client.server.Limits().LineLen.Rest - 110
}
lines := wordWrap(text, limit)

View File

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

View File

@ -335,7 +335,7 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
return false
}
targetNick := target.getNick()
targetNick := target.Nick()
hasPrivs := client == target || msg.Command == "SAMODE"
if !hasPrivs {
@ -513,9 +513,9 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
switch change.op {
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] {
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
}
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.
func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
cfnick := client.getNickCasefolded()
nick := client.getNick()
cfnick := client.NickCasefolded()
nick := client.Nick()
var watchers []*Client
// safely copy the list of clients watching our nick
manager.RLock()
@ -53,7 +53,7 @@ func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
}
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])]
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
}
@ -132,7 +132,7 @@ func monitorHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
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
}
@ -150,14 +150,14 @@ func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
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
}
var online []string
var offline []string
limit := server.getLimits().MonitorEntries
limit := server.Limits().MonitorEntries
targets := strings.Split(msg.Params[1], ",")
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)
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
} else if err != nil {
continue
@ -184,15 +184,15 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
if targetClient := server.clients.Get(casefoldedTarget); targetClient == nil {
offline = append(offline, target)
} else {
online = append(online, targetClient.getNick())
online = append(online, targetClient.Nick())
}
}
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 {
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
@ -211,13 +211,13 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
replynick := cfnick
// report the uncasefolded nick if it's available, i.e., the client is online
if mclient := server.clients.Get(cfnick); mclient != nil {
replynick = mclient.getNick()
replynick = mclient.Nick()
}
nickList = append(nickList, replynick)
}
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")
@ -236,18 +236,18 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
if target == nil {
offline = append(offline, name)
} else {
online = append(online, target.getNick())
online = append(online, target.Nick())
}
}
if len(online) > 0 {
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 {
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
}
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")
return false
}

View File

@ -577,7 +577,7 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) (resul
default:
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])
@ -697,7 +697,7 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
}
err := server.channels.Join(client, name, key)
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
@ -1044,7 +1044,7 @@ func (target *Client) rplWhoReply(channel *Channel, client *Client) {
flags += channel.ClientPrefixes(client, target.capabilities.Has(caps.MultiPrefix))
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) {
@ -1586,7 +1586,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if len(msg.Params) > 0 {
isAway = true
text = msg.Params[0]
awayLen := server.getLimits().AwayLen
awayLen := server.Limits().AwayLen
if len(text) > awayLen {
text = text[:awayLen]
}