Browse Source

rename some getters

Rename getters in conformance with the "Effective Go" styleguide recommendation:
https://golang.org/doc/effective_go.html#Getters
tags/v0.10.1
Shivaram Lingamneni 6 years ago
parent
commit
9b74c47b74
8 changed files with 43 additions and 43 deletions
  1. 8
    8
      irc/channel.go
  2. 1
    1
      irc/channelmanager.go
  3. 4
    4
      irc/client.go
  4. 6
    6
      irc/getters.go
  5. 3
    3
      irc/modes.go
  6. 16
    16
      irc/monitor.go
  7. 1
    1
      irc/nickname.go
  8. 4
    4
      irc/server.go

+ 8
- 8
irc/channel.go View File

@@ -211,9 +211,9 @@ func (channel *Channel) nicks(target *Client) []string {
211 211
 	i = 0
212 212
 	for i < length {
213 213
 		if isUserhostInNames {
214
-			result[i] += clients[i].getNickMaskString()
214
+			result[i] += clients[i].NickMaskString()
215 215
 		} else {
216
-			result[i] += clients[i].getNick()
216
+			result[i] += clients[i].Nick()
217 217
 		}
218 218
 		i++
219 219
 	}
@@ -644,7 +644,7 @@ func (channel *Channel) ShowMaskList(client *Client, mode Mode) {
644 644
 		rplendoflist = RPL_ENDOFINVITELIST
645 645
 	}
646 646
 
647
-	nick := client.getNick()
647
+	nick := client.Nick()
648 648
 	channel.stateMutex.RLock()
649 649
 	// XXX don't acquire any new locks in this section, besides Socket.Write
650 650
 	for mask := range channel.lists[mode].masks {
@@ -711,13 +711,13 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
711 711
 		return
712 712
 	}
713 713
 
714
-	kicklimit := client.server.getLimits().KickLen
714
+	kicklimit := client.server.Limits().KickLen
715 715
 	if len(comment) > kicklimit {
716 716
 		comment = comment[:kicklimit]
717 717
 	}
718 718
 
719
-	clientMask := client.getNickMaskString()
720
-	targetNick := target.getNick()
719
+	clientMask := client.NickMaskString()
720
+	targetNick := target.Nick()
721 721
 	for _, member := range channel.Members() {
722 722
 		member.Send(nil, clientMask, "KICK", channel.name, targetNick, comment)
723 723
 	}
@@ -739,7 +739,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
739 739
 
740 740
 	//TODO(dan): handle this more nicely, keep a list of last X invited channels on invitee rather than explicitly modifying the invite list?
741 741
 	if channel.flags[InviteOnly] {
742
-		nmc := invitee.getNickCasefolded()
742
+		nmc := invitee.NickCasefolded()
743 743
 		channel.stateMutex.Lock()
744 744
 		channel.lists[InviteMask].Add(nmc)
745 745
 		channel.stateMutex.Unlock()
@@ -747,7 +747,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
747 747
 
748 748
 	for _, member := range channel.Members() {
749 749
 		if member.capabilities.Has(caps.InviteNotify) && member != inviter && member != invitee && channel.ClientIsAtLeast(member, Halfop) {
750
-			member.Send(nil, inviter.getNickMaskString(), "INVITE", invitee.getNick(), channel.name)
750
+			member.Send(nil, inviter.NickMaskString(), "INVITE", invitee.Nick(), channel.name)
751 751
 		}
752 752
 	}
753 753
 

+ 1
- 1
irc/channelmanager.go View File

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

+ 4
- 4
irc/client.go View File

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

+ 6
- 6
irc/getters.go View File

@@ -5,19 +5,19 @@ package irc
5 5
 
6 6
 import "github.com/oragono/oragono/irc/isupport"
7 7
 
8
-func (server *Server) getISupport() *isupport.List {
8
+func (server *Server) ISupport() *isupport.List {
9 9
 	server.configurableStateMutex.RLock()
10 10
 	defer server.configurableStateMutex.RUnlock()
11 11
 	return server.isupport
12 12
 }
13 13
 
14
-func (server *Server) getLimits() Limits {
14
+func (server *Server) Limits() Limits {
15 15
 	server.configurableStateMutex.RLock()
16 16
 	defer server.configurableStateMutex.RUnlock()
17 17
 	return server.limits
18 18
 }
19 19
 
20
-func (server *Server) getPassword() []byte {
20
+func (server *Server) Password() []byte {
21 21
 	server.configurableStateMutex.RLock()
22 22
 	defer server.configurableStateMutex.RUnlock()
23 23
 	return server.password
@@ -47,19 +47,19 @@ func (server *Server) DefaultChannelModes() Modes {
47 47
 	return server.defaultChannelModes
48 48
 }
49 49
 
50
-func (client *Client) getNick() string {
50
+func (client *Client) Nick() string {
51 51
 	client.stateMutex.RLock()
52 52
 	defer client.stateMutex.RUnlock()
53 53
 	return client.nick
54 54
 }
55 55
 
56
-func (client *Client) getNickMaskString() string {
56
+func (client *Client) NickMaskString() string {
57 57
 	client.stateMutex.RLock()
58 58
 	defer client.stateMutex.RUnlock()
59 59
 	return client.nickMaskString
60 60
 }
61 61
 
62
-func (client *Client) getNickCasefolded() string {
62
+func (client *Client) NickCasefolded() string {
63 63
 	client.stateMutex.RLock()
64 64
 	defer client.stateMutex.RUnlock()
65 65
 	return client.nickCasefolded

+ 3
- 3
irc/modes.go View File

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

+ 16
- 16
irc/monitor.go View File

@@ -37,8 +37,8 @@ var ErrMonitorLimitExceeded = errors.New("Monitor limit exceeded")
37 37
 
38 38
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
39 39
 func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
40
-	cfnick := client.getNickCasefolded()
41
-	nick := client.getNick()
40
+	cfnick := client.NickCasefolded()
41
+	nick := client.Nick()
42 42
 	var watchers []*Client
43 43
 	// safely copy the list of clients watching our nick
44 44
 	manager.RLock()
@@ -53,7 +53,7 @@ func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
53 53
 	}
54 54
 
55 55
 	for _, mClient := range watchers {
56
-		mClient.Send(nil, client.server.name, command, mClient.getNick(), nick)
56
+		mClient.Send(nil, client.server.name, command, mClient.Nick(), nick)
57 57
 	}
58 58
 }
59 59
 
@@ -123,7 +123,7 @@ func monitorHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
123 123
 	handler, exists := metadataSubcommands[strings.ToLower(msg.Params[0])]
124 124
 
125 125
 	if !exists {
126
-		client.Send(nil, server.name, ERR_UNKNOWNERROR, client.getNick(), "MONITOR", msg.Params[0], "Unknown subcommand")
126
+		client.Send(nil, server.name, ERR_UNKNOWNERROR, client.Nick(), "MONITOR", msg.Params[0], "Unknown subcommand")
127 127
 		return false
128 128
 	}
129 129
 
@@ -132,7 +132,7 @@ func monitorHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
132 132
 
133 133
 func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
134 134
 	if len(msg.Params) < 2 {
135
-		client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.getNick(), msg.Command, "Not enough parameters")
135
+		client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.Nick(), msg.Command, "Not enough parameters")
136 136
 		return false
137 137
 	}
138 138
 
@@ -150,14 +150,14 @@ func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
150 150
 
151 151
 func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
152 152
 	if len(msg.Params) < 2 {
153
-		client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.getNick(), msg.Command, "Not enough parameters")
153
+		client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.Nick(), msg.Command, "Not enough parameters")
154 154
 		return false
155 155
 	}
156 156
 
157 157
 	var online []string
158 158
 	var offline []string
159 159
 
160
-	limit := server.getLimits().MonitorEntries
160
+	limit := server.Limits().MonitorEntries
161 161
 
162 162
 	targets := strings.Split(msg.Params[1], ",")
163 163
 	for _, target := range targets {
@@ -174,7 +174,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
174 174
 
175 175
 		err = server.monitorManager.Add(client, casefoldedTarget, limit)
176 176
 		if err == ErrMonitorLimitExceeded {
177
-			client.Send(nil, server.name, ERR_MONLISTFULL, client.getNick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
177
+			client.Send(nil, server.name, ERR_MONLISTFULL, client.Nick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
178 178
 			break
179 179
 		} else if err != nil {
180 180
 			continue
@@ -184,15 +184,15 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
184 184
 		if targetClient := server.clients.Get(casefoldedTarget); targetClient == nil {
185 185
 			offline = append(offline, target)
186 186
 		} else {
187
-			online = append(online, targetClient.getNick())
187
+			online = append(online, targetClient.Nick())
188 188
 		}
189 189
 	}
190 190
 
191 191
 	if len(online) > 0 {
192
-		client.Send(nil, server.name, RPL_MONONLINE, client.getNick(), strings.Join(online, ","))
192
+		client.Send(nil, server.name, RPL_MONONLINE, client.Nick(), strings.Join(online, ","))
193 193
 	}
194 194
 	if len(offline) > 0 {
195
-		client.Send(nil, server.name, RPL_MONOFFLINE, client.getNick(), strings.Join(offline, ","))
195
+		client.Send(nil, server.name, RPL_MONOFFLINE, client.Nick(), strings.Join(offline, ","))
196 196
 	}
197 197
 
198 198
 	return false
@@ -211,13 +211,13 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
211 211
 		replynick := cfnick
212 212
 		// report the uncasefolded nick if it's available, i.e., the client is online
213 213
 		if mclient := server.clients.Get(cfnick); mclient != nil {
214
-			replynick = mclient.getNick()
214
+			replynick = mclient.Nick()
215 215
 		}
216 216
 		nickList = append(nickList, replynick)
217 217
 	}
218 218
 
219 219
 	for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") {
220
-		client.Send(nil, server.name, RPL_MONLIST, client.getNick(), line)
220
+		client.Send(nil, server.name, RPL_MONLIST, client.Nick(), line)
221 221
 	}
222 222
 
223 223
 	client.Send(nil, server.name, RPL_ENDOFMONLIST, "End of MONITOR list")
@@ -236,18 +236,18 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
236 236
 		if target == nil {
237 237
 			offline = append(offline, name)
238 238
 		} else {
239
-			online = append(online, target.getNick())
239
+			online = append(online, target.Nick())
240 240
 		}
241 241
 	}
242 242
 
243 243
 	if len(online) > 0 {
244 244
 		for _, line := range utils.ArgsToStrings(maxLastArgLength, online, ",") {
245
-			client.Send(nil, server.name, RPL_MONONLINE, client.getNick(), line)
245
+			client.Send(nil, server.name, RPL_MONONLINE, client.Nick(), line)
246 246
 		}
247 247
 	}
248 248
 	if len(offline) > 0 {
249 249
 		for _, line := range utils.ArgsToStrings(maxLastArgLength, offline, ",") {
250
-			client.Send(nil, server.name, RPL_MONOFFLINE, client.getNick(), line)
250
+			client.Send(nil, server.name, RPL_MONOFFLINE, client.Nick(), line)
251 251
 		}
252 252
 	}
253 253
 

+ 1
- 1
irc/nickname.go View File

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

+ 4
- 4
irc/server.go View File

@@ -577,7 +577,7 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) (resul
577 577
 		default:
578 578
 			code = ERR_UNKNOWNERROR
579 579
 		}
580
-		client.Send(nil, server.name, code, client.getNick(), "RENAME", name, err.Error())
580
+		client.Send(nil, server.name, code, client.Nick(), "RENAME", name, err.Error())
581 581
 	}
582 582
 
583 583
 	oldName := strings.TrimSpace(msg.Params[0])
@@ -697,7 +697,7 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
697 697
 		}
698 698
 		err := server.channels.Join(client, name, key)
699 699
 		if err == NoSuchChannel {
700
-			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.getNick(), name, "No such channel")
700
+			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), name, "No such channel")
701 701
 		}
702 702
 	}
703 703
 	return false
@@ -1044,7 +1044,7 @@ func (target *Client) rplWhoReply(channel *Channel, client *Client) {
1044 1044
 		flags += channel.ClientPrefixes(client, target.capabilities.Has(caps.MultiPrefix))
1045 1045
 		channelName = channel.name
1046 1046
 	}
1047
-	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())
1047
+	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())
1048 1048
 }
1049 1049
 
1050 1050
 func whoChannel(client *Client, channel *Channel, friends ClientSet) {
@@ -1586,7 +1586,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1586 1586
 	if len(msg.Params) > 0 {
1587 1587
 		isAway = true
1588 1588
 		text = msg.Params[0]
1589
-		awayLen := server.getLimits().AwayLen
1589
+		awayLen := server.Limits().AwayLen
1590 1590
 		if len(text) > awayLen {
1591 1591
 			text = text[:awayLen]
1592 1592
 		}

Loading…
Cancel
Save