From eb02aadf56ea02634e6fd662cee320363b00ab1b Mon Sep 17 00:00:00 2001 From: CodeLingo Bot Date: Mon, 11 Mar 2019 00:56:12 +0000 Subject: [PATCH] Fix function comments based on best practices from Effective Go Signed-off-by: CodeLingo Bot --- cmd/grumble/channel.go | 20 ++++++++-------- cmd/grumble/client.go | 14 +++++------ cmd/grumble/freeze.go | 8 +++---- cmd/grumble/server.go | 30 +++++++++++------------ cmd/grumble/user.go | 8 +++---- cmd/grumble/voicetarget.go | 6 ++--- pkg/acl/group.go | 2 +- pkg/ban/ban.go | 6 ++--- pkg/mumbleproto/types.go | 2 +- pkg/packetdata/packetdata.go | 46 ++++++++++++++++++------------------ pkg/serverconf/config.go | 10 ++++---- 11 files changed, 76 insertions(+), 76 deletions(-) diff --git a/cmd/grumble/channel.go b/cmd/grumble/channel.go index b6056f3..7d38863 100644 --- a/cmd/grumble/channel.go +++ b/cmd/grumble/channel.go @@ -41,38 +41,38 @@ func NewChannel(id int, name string) (channel *Channel) { return } -// Add a child channel to a channel +// AddChild adds a child channel to a channel func (channel *Channel) AddChild(child *Channel) { child.parent = channel child.ACL.Parent = &channel.ACL channel.children[child.Id] = child } -// Remove a child channel from a parent +// RemoveChild removes a child channel from a parent func (channel *Channel) RemoveChild(child *Channel) { child.parent = nil child.ACL.Parent = nil delete(channel.children, child.Id) } -// Add client +// AddClient adds client func (channel *Channel) AddClient(client *Client) { channel.clients[client.Session()] = client client.Channel = channel } -// Remove client +// RemoveClient removes client func (channel *Channel) RemoveClient(client *Client) { delete(channel.clients, client.Session()) client.Channel = nil } -// Does the channel have a description? +// HasDescription Does the channel have a description? func (channel *Channel) HasDescription() bool { return len(channel.DescriptionBlob) > 0 } -// Get the channel's blob hash as a byte slice for sending via a protobuf message. +// DescriptionBlobHashBytes gets the channel's blob hash as a byte slice for sending via a protobuf message. // Returns nil if there is no blob. func (channel *Channel) DescriptionBlobHashBytes() (buf []byte) { buf, err := hex.DecodeString(channel.DescriptionBlob) @@ -82,7 +82,7 @@ func (channel *Channel) DescriptionBlobHashBytes() (buf []byte) { return buf } -// Returns a slice of all channels in this channel's +// AllLinks returns a slice of all channels in this channel's // link chain. func (channel *Channel) AllLinks() (seen map[int]*Channel) { seen = make(map[int]*Channel) @@ -100,7 +100,7 @@ func (channel *Channel) AllLinks() (seen map[int]*Channel) { return } -// Returns a slice of all of this channel's subchannels. +// AllSubChannels returns a slice of all of this channel's subchannels. func (channel *Channel) AllSubChannels() (seen map[int]*Channel) { seen = make(map[int]*Channel) walk := []*Channel{} @@ -120,12 +120,12 @@ func (channel *Channel) AllSubChannels() (seen map[int]*Channel) { return } -// Checks whether the channel is temporary +// IsTemporary checks whether the channel is temporary func (channel *Channel) IsTemporary() bool { return channel.temporary } -// Checks whether the channel is temporary +// IsEmpty checks whether the channel is temporary func (channel *Channel) IsEmpty() bool { return len(channel.clients) == 0 } diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 4143ba0..493e25a 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -96,17 +96,17 @@ func (client *Client) Debugf(format string, v ...interface{}) { client.Printf(format, v...) } -// Is the client a registered user? +// IsRegistered Is the client a registered user? func (client *Client) IsRegistered() bool { return client.user != nil } -// Does the client have a certificate? +// HasCertificate Does the client have a certificate? func (client *Client) HasCertificate() bool { return len(client.certHash) > 0 } -// Is the client the SuperUser? +// IsSuperUser Is the client the SuperUser? func (client *Client) IsSuperUser() bool { if client.user == nil { return false @@ -130,7 +130,7 @@ func (client *Client) Tokens() []string { return client.tokens } -// Get the User ID of this client. +// UserId gets the User ID of this client. // Returns -1 if the client is not a registered user. func (client *Client) UserId() int { if client.user == nil { @@ -139,7 +139,7 @@ func (client *Client) UserId() int { return int(client.user.Id) } -// Get the client's shown name. +// ShownName gets the client's shown name. func (client *Client) ShownName() string { if client.IsSuperUser() { return "SuperUser" @@ -150,7 +150,7 @@ func (client *Client) ShownName() string { return client.Username } -// Check whether the client's certificate is +// IsVerified checks whether the client's certificate is // verified. func (client *Client) IsVerified() bool { tlsconn := client.conn.(*tls.Conn) @@ -207,7 +207,7 @@ func (client *Client) ForceDisconnect() { client.disconnect(true) } -// Clear the client's caches +// ClearCaches clears the client's caches func (client *Client) ClearCaches() { for _, vt := range client.voiceTargets { vt.ClearCache() diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index edd7f7f..b2937a2 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -776,7 +776,7 @@ func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.C server.numLogOps += 1 } -// Write a channel's ACL and Group data to disk. Mumble doesn't support +// UpdateFrozenChannelACLs writes a channel's ACL and Group data to disk. Mumble doesn't support // incremental ACL updates and as such we must write all ACLs and groups // to the datastore on each change. func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { @@ -821,7 +821,7 @@ func (server *Server) DeleteFrozenChannel(channel *Channel) { server.numLogOps += 1 } -// Write the server's banlist to the datastore. +// UpdateFrozenBans writes the server's banlist to the datastore. func (server *Server) UpdateFrozenBans(bans []ban.Ban) { fbl := &freezer.BanList{} for _, ban := range server.Bans { @@ -834,7 +834,7 @@ func (server *Server) UpdateFrozenBans(bans []ban.Ban) { server.numLogOps += 1 } -// Write an updated config value to the datastore. +// UpdateConfig writes an updated config value to the datastore. func (server *Server) UpdateConfig(key, value string) { fcfg := &freezer.ConfigKeyValuePair{ Key: proto.String(key), @@ -847,7 +847,7 @@ func (server *Server) UpdateConfig(key, value string) { server.numLogOps += 1 } -// Write to the freezelog that the config with key +// ResetConfig writes to the freezelog that the config with key // has been reset to its default value. func (server *Server) ResetConfig(key string) { fcfg := &freezer.ConfigKeyValuePair{ diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index f6f627a..ddf67bd 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -165,7 +165,7 @@ func (server *Server) Debugf(format string, v ...interface{}) { server.Printf(format, v...) } -// Get a pointer to the root channel +// RootChannel gets a pointer to the root channel func (server *Server) RootChannel() *Channel { root, exists := server.Channels[0] if !exists { @@ -195,7 +195,7 @@ func (server *Server) SetSuperUserPassword(password string) { server.cfgUpdate <- &KeyValuePair{Key: key, Value: val} } -// Check whether password matches the set SuperUser password. +// CheckSuperUserPassword checks whether password matches the set SuperUser password. func (server *Server) CheckSuperUserPassword(password string) bool { parts := strings.Split(server.cfg.StringValue("SuperUserPassword"), "$") if len(parts) != 3 { @@ -296,7 +296,7 @@ func (server *Server) handleIncomingClient(conn net.Conn) (err error) { return } -// Remove a disconnected client from the server's +// RemoveClient removes a disconnected client from the server's // internal representation. func (server *Server) RemoveClient(client *Client, kicked bool) { server.hmutex.Lock() @@ -336,7 +336,7 @@ func (server *Server) RemoveClient(client *Client, kicked bool) { } } -// Add a new channel to the server. Automatically assign it a channel ID. +// AddChannel adds a new channel to the server. Automatically assign it a channel ID. func (server *Server) AddChannel(name string) (channel *Channel) { channel = NewChannel(server.nextChanId, name) server.Channels[channel.Id] = channel @@ -345,7 +345,7 @@ func (server *Server) AddChannel(name string) (channel *Channel) { return } -// Remove a channel from the server. +// RemoveChanel removes a channel from the server. func (server *Server) RemoveChanel(channel *Channel) { if channel.Id == 0 { server.Printf("Attempted to remove root channel.") @@ -1047,7 +1047,7 @@ func (server *Server) handleUdpPacket(udpaddr *net.UDPAddr, buf []byte) { match.udprecv <- plain } -// Clear the Server's caches +// ClearCaches clears the Server's caches func (server *Server) ClearCaches() { for _, client := range server.clients { client.ClearCaches() @@ -1115,7 +1115,7 @@ func (s *Server) RegisterClient(client *Client) (uid uint32, err error) { return uid, nil } -// Remove a registered user. +// RemoveRegistration removes a registered user. func (s *Server) RemoveRegistration(uid uint32) (err error) { user, ok := s.Users[uid] if !ok { @@ -1162,7 +1162,7 @@ func (s *Server) removeRegisteredUserFromChannel(uid uint32, channel *Channel) { } } -// Remove a channel +// RemoveChannel removes a channel func (server *Server) RemoveChannel(channel *Channel) { // Can't remove root if channel == server.RootChannel() { @@ -1207,7 +1207,7 @@ func (server *Server) RemoveChannel(channel *Channel) { } } -// Remove expired bans +// RemoveExpiredBans removes expired bans func (server *Server) RemoveExpiredBans() { server.banlock.Lock() defer server.banlock.Unlock() @@ -1228,7 +1228,7 @@ func (server *Server) RemoveExpiredBans() { } } -// Is the incoming connection conn banned? +// IsConnectionBanned Is the incoming connection conn banned? func (server *Server) IsConnectionBanned(conn net.Conn) bool { server.banlock.RLock() defer server.banlock.RUnlock() @@ -1243,7 +1243,7 @@ func (server *Server) IsConnectionBanned(conn net.Conn) bool { return false } -// Is the certificate hash banned? +// IsCertHashBanned Is the certificate hash banned? func (server *Server) IsCertHashBanned(hash string) bool { server.banlock.RLock() defer server.banlock.RUnlock() @@ -1344,7 +1344,7 @@ func (server *Server) cleanPerLaunchData() { server.clientAuthenticated = nil } -// Returns the port the native server will listen on when it is +// Port returns the port the native server will listen on when it is // started. func (server *Server) Port() int { port := server.cfg.IntValue("Port") @@ -1354,7 +1354,7 @@ func (server *Server) Port() int { return port } -// Returns the port the web server will listen on when it is +// WebPort returns the port the web server will listen on when it is // started. func (server *Server) WebPort() int { port := server.cfg.IntValue("WebPort") @@ -1364,7 +1364,7 @@ func (server *Server) WebPort() int { return port } -// Returns the port the native server is currently listening +// CurrentPort returns the port the native server is currently listening // on. If called when the server is not running, // this function returns -1. func (server *Server) CurrentPort() int { @@ -1375,7 +1375,7 @@ func (server *Server) CurrentPort() int { return tcpaddr.Port } -// Returns the host address the server will listen on when +// HostAddress returns the host address the server will listen on when // it is started. This must be an IP address, either IPv4 // or IPv6. func (server *Server) HostAddress() string { diff --git a/cmd/grumble/user.go b/cmd/grumble/user.go index f922efb..8346514 100644 --- a/cmd/grumble/user.go +++ b/cmd/grumble/user.go @@ -40,12 +40,12 @@ func NewUser(id uint32, name string) (user *User, err error) { }, nil } -// Does the channel have comment? +// HasComment Does the channel have comment? func (user *User) HasComment() bool { return len(user.CommentBlob) > 0 } -// Get the hash of the user's comment blob as a byte slice for transmitting via a protobuf message. +// CommentBlobHashBytes gets the hash of the user's comment blob as a byte slice for transmitting via a protobuf message. // Returns nil if there is no such blob. func (user *User) CommentBlobHashBytes() (buf []byte) { buf, err := hex.DecodeString(user.CommentBlob) @@ -55,12 +55,12 @@ func (user *User) CommentBlobHashBytes() (buf []byte) { return buf } -// Does the user have a texture? +// HasTexture Does the user have a texture? func (user *User) HasTexture() bool { return len(user.TextureBlob) > 0 } -// Get the hash of the user's texture blob as a byte slice for transmitting via a protobuf message. +// TextureBlobHashBytes gets the hash of the user's texture blob as a byte slice for transmitting via a protobuf message. // Returns nil if there is no such blob. func (user *User) TextureBlobHashBytes() (buf []byte) { buf, err := hex.DecodeString(user.TextureBlob) diff --git a/cmd/grumble/voicetarget.go b/cmd/grumble/voicetarget.go index d868b9b..4c8453e 100644 --- a/cmd/grumble/voicetarget.go +++ b/cmd/grumble/voicetarget.go @@ -28,7 +28,7 @@ func (vt *VoiceTarget) AddSession(session uint32) { vt.sessions = append(vt.sessions, session) } -// Add a channel to the VoiceTarget. +// AddChannel adds a channel to the VoiceTarget. // If subchannels is true, any sent voice packets will also be sent to all subchannels. // If links is true, any sent voice packets will also be sent to all linked channels. // If group is a non-empty string, any sent voice packets will only be broadcast to members @@ -42,12 +42,12 @@ func (vt *VoiceTarget) AddChannel(id uint32, subchannels bool, links bool, group }) } -// Checks whether the VoiceTarget is empty (has no targets) +// IsEmpty checks whether the VoiceTarget is empty (has no targets) func (vt *VoiceTarget) IsEmpty() bool { return len(vt.sessions) == 0 && len(vt.channels) == 0 } -// Clear the VoiceTarget's cache. +// ClearCache clears the VoiceTarget's cache. func (vt *VoiceTarget) ClearCache() { vt.directCache = nil vt.fromChannelsCache = nil diff --git a/pkg/acl/group.go b/pkg/acl/group.go index db3d039..c533668 100644 --- a/pkg/acl/group.go +++ b/pkg/acl/group.go @@ -336,7 +336,7 @@ func GroupMemberCheck(current *Context, acl *Context, name string, user User) (o return false } -// Get the list of group names for the given ACL context. +// GroupNames gets the list of group names for the given ACL context. // // This function walks the through the context chain to figure // out all groups that affect the given context whilst considering diff --git a/pkg/ban/ban.go b/pkg/ban/ban.go index 0e03d35..6bd9dcf 100644 --- a/pkg/ban/ban.go +++ b/pkg/ban/ban.go @@ -41,7 +41,7 @@ func (ban Ban) IPMask() (mask net.IPMask) { return } -// Check whether an IP matches a Ban +// Match checks whether an IP matches a Ban func (ban Ban) Match(ip net.IP) bool { banned := ban.IP.Mask(ban.IPMask()) masked := ip.Mask(ban.IPMask()) @@ -58,14 +58,14 @@ func (ban *Ban) SetISOStartDate(isodate string) { } } -// Return the currently set start date as an ISO 8601-formatted +// ISOStartDate returns the currently set start date as an ISO 8601-formatted // date (in UTC). func (ban Ban) ISOStartDate() string { startTime := time.Unix(ban.Start, 0).UTC() return startTime.Format(ISODate) } -// Check whether a ban has expired +// IsExpired checks whether a ban has expired func (ban Ban) IsExpired() bool { // ∞-case if ban.Duration == 0 { diff --git a/pkg/mumbleproto/types.go b/pkg/mumbleproto/types.go index d2068ce..b8e442c 100644 --- a/pkg/mumbleproto/types.go +++ b/pkg/mumbleproto/types.go @@ -40,7 +40,7 @@ const ( UDPMessageVoiceOpus ) -// Returns the numeric value identifying the message type of msg on the wire. +// MessageType returns the numeric value identifying the message type of msg on the wire. func MessageType(msg interface{}) uint16 { switch msg.(type) { case *Version: diff --git a/pkg/packetdata/packetdata.go b/pkg/packetdata/packetdata.go index bea6966..f71e61f 100644 --- a/pkg/packetdata/packetdata.go +++ b/pkg/packetdata/packetdata.go @@ -37,13 +37,13 @@ func (pds *PacketData) Skip(skip int) { } } -// Returns number of bytes remaining in +// Left returns number of bytes remaining in // the buffer. func (pds *PacketData) Left() int { return int(pds.maxsize - pds.offset) } -// Returns the size of the currently-assembled data +// Size returns the size of the currently-assembled data // stream func (pds *PacketData) Size() int { return pds.offset @@ -61,7 +61,7 @@ func (pds *PacketData) next() (ret uint64) { return 0 } -// Get the next byte from the PacketData as a byte (uint8) +// Next8 gets the next byte from the PacketData as a byte (uint8) func (pds *PacketData) Next8() (ret uint8) { if pds.offset < pds.maxsize { ret = uint8(pds.Buf[pds.offset]) @@ -170,88 +170,88 @@ func (pds *PacketData) getVarint() (i uint64) { return } -// Read a uint64 from the PacketData +// GetUint64 reads a uint64 from the PacketData func (pds *PacketData) GetUint64() uint64 { return pds.getVarint() } -// Write a uint64 to the PacketData +// PutUint64 writes a uint64 to the PacketData func (pds *PacketData) PutUint64(val uint64) { pds.addVarint(val) } -// Read a uint32 from the PacketData +// GetUint32 reads a uint32 from the PacketData func (pds *PacketData) GetUint32() uint32 { return uint32(pds.getVarint()) } -// Write a uint32 to the PacketData +// PutUint32 writes a uint32 to the PacketData func (pds *PacketData) PutUint32(val uint32) { pds.addVarint(uint64(val)) } -// Read a uint16 from the PacketData +// GetUint16 reads a uint16 from the PacketData func (pds *PacketData) GetUint16() uint16 { return uint16(pds.getVarint()) } -// Write a uint16 to the PacketData +// PutUint16 writes a uint16 to the PacketData func (pds *PacketData) PutUint16(val uint16) { pds.addVarint(uint64(val)) } -// Read a uint8 from the PacketData +// GetUint8 reads a uint8 from the PacketData func (pds *PacketData) GetUint8() uint8 { varint := pds.getVarint() return uint8(varint) } -// Write a uint8 to the PacketData +// PutUint8 writes a uint8 to the PacketData func (pds *PacketData) PutUint8(val uint8) { pds.addVarint(uint64(val)) } -// Read a int64 from the PacketData +// GetInt64 reads a int64 from the PacketData func (pds *PacketData) GetInt64() int64 { return int64(pds.getVarint()) } -// Write a int64 to the PacketData +// PutInt64 writes a int64 to the PacketData func (pds *PacketData) PutInt64(val int64) { pds.addVarint(uint64(val)) } -// Read a int32 from the PacketData +// GetInt32 reads a int32 from the PacketData func (pds *PacketData) GetInt32() int32 { return int32(pds.getVarint()) } -// Write a int32 to the PacketData +// PutInt32 writes a int32 to the PacketData func (pds *PacketData) PutInt32(val int32) { pds.addVarint(uint64(val)) } -// Read a int16 from the PacketData +// GetInt16 reads a int16 from the PacketData func (pds *PacketData) GetInt16() int16 { return int16(pds.getVarint()) } -// Write a int16 to the PacketData +// PutInt16 writes a int16 to the PacketData func (pds *PacketData) PutInt16(val int16) { pds.addVarint(uint64(val)) } -// Read a int8 from the PacketData +// GetInt8 reads a int8 from the PacketData func (pds *PacketData) GetInt8() int8 { return int8(pds.getVarint()) } -// Write a int8 to the PacketData +// PutInt8 writes a int8 to the PacketData func (pds *PacketData) PutInt8(val int8) { pds.addVarint(uint64(val)) } -// Read a float32 from the PacketData +// GetFloat32 reads a float32 from the PacketData func (pds *PacketData) GetFloat32() float32 { if pds.Left() < 4 { pds.ok = false @@ -264,7 +264,7 @@ func (pds *PacketData) GetFloat32() float32 { return math.Float32frombits(val) } -// Write a float32 to the PacketData +// PutFloat32 writes a float32 to the PacketData func (pds *PacketData) PutFloat32(val float32) { bits := math.Float32bits(val) pds.append(uint64((bits >> 24) & 0xff)) @@ -273,7 +273,7 @@ func (pds *PacketData) PutFloat32(val float32) { pds.append(uint64(bits & 0xff)) } -// Read a float64 from the PacketData. +// GetFloat64 reads a float64 from the PacketData. func (pds *PacketData) GetFloat64() float64 { if pds.Left() < 8 { pds.ok = false @@ -286,7 +286,7 @@ func (pds *PacketData) GetFloat64() float64 { return math.Float64frombits(val) } -// Write a float64 to the PacketData +// PutFloat64 writes a float64 to the PacketData func (pds *PacketData) PutFloat64(val float64) { bits := math.Float64bits(val) pds.append((bits >> 56) & 0xff) diff --git a/pkg/serverconf/config.go b/pkg/serverconf/config.go index bf0c28b..0eb26d1 100644 --- a/pkg/serverconf/config.go +++ b/pkg/serverconf/config.go @@ -36,7 +36,7 @@ func New(cfgMap map[string]string) *Config { return &Config{cfgMap: cfgMap} } -// Get a copy of the Config's internal config map +// GetAll gets a copy of the Config's internal config map func (cfg *Config) GetAll() (all map[string]string) { cfg.mutex.RLock() defer cfg.mutex.RUnlock() @@ -62,7 +62,7 @@ func (cfg *Config) Reset(key string) { delete(cfg.cfgMap, key) } -// Get the value of a specific config key encoded as a string +// StringValue gets the value of a specific config key encoded as a string func (cfg *Config) StringValue(key string) (value string) { cfg.mutex.RLock() defer cfg.mutex.RUnlock() @@ -80,21 +80,21 @@ func (cfg *Config) StringValue(key string) (value string) { return "" } -// Get the value of a speific config key as an int +// IntValue gets the value of a speific config key as an int func (cfg *Config) IntValue(key string) (intval int) { str := cfg.StringValue(key) intval, _ = strconv.Atoi(str) return } -// Get the value of a specific config key as a uint32 +// Uint32Value gets the value of a specific config key as a uint32 func (cfg *Config) Uint32Value(key string) (uint32val uint32) { str := cfg.StringValue(key) uintval, _ := strconv.ParseUint(str, 10, 0) return uint32(uintval) } -// Get the value fo a sepcific config key as a bool +// BoolValue gets the value fo a sepcific config key as a bool func (cfg *Config) BoolValue(key string) (boolval bool) { str := cfg.StringValue(key) boolval, _ = strconv.ParseBool(str)