Making a dent in golint: 94 -> 70
authorAndrey Petrov <andrey.petrov@shazow.net>
Sat, 27 Dec 2014 01:59:29 +0000 (17:59 -0800)
committerAndrey Petrov <andrey.petrov@shazow.net>
Sat, 27 Dec 2014 01:59:29 +0000 (17:59 -0800)
chat/channel.go
chat/command.go
chat/set.go
host.go

index 2107419b7f2850a6c2976455131bfe9aa50076c0..646fe0cb0dbe6782a24110156678dde64e1a5d26 100644 (file)
@@ -9,6 +9,8 @@ import (
 const historyLen = 20
 const channelBuffer = 10
 
+// The error returned when a message is sent to a channel that is already
+// closed.
 var ErrChannelClosed = errors.New("channel closed")
 
 // Channel definition, also a Set of User Items
@@ -22,7 +24,7 @@ type Channel struct {
        closeOnce sync.Once
 }
 
-// Create new channel and start broadcasting goroutine.
+// NewChannel creates a new channel.
 func NewChannel() *Channel {
        broadcast := make(chan Message, channelBuffer)
 
@@ -46,7 +48,7 @@ func (ch *Channel) Close() {
        })
 }
 
-// Handle a message, will block until done.
+// HandleMsg reacts to a message, will block until done.
 func (ch *Channel) HandleMsg(m Message) {
        switch m := m.(type) {
        case *CommandMsg:
index 022566271afcc264e79d58318fba5abd9691462a..cb329d1e1fd1a16d88489242f31b12002cb84078 100644 (file)
@@ -8,18 +8,27 @@ import (
        "sync"
 )
 
+// The error returned when an invalid command is issued.
 var ErrInvalidCommand = errors.New("invalid command")
+
+// The error returned when a command is given without an owner.
 var ErrNoOwner = errors.New("command without owner")
+
+// The error returned when a command is performed without the necessary number
+// of arguments.
 var ErrMissingArg = errors.New("missing argument")
 
+// CommandHandler is the function signature for command handlers..
 type CommandHandler func(*Channel, CommandMsg) error
 
+// Commands is a registry of available commands.
 type Commands struct {
        handlers map[string]CommandHandler
        help     map[string]string
        sync.RWMutex
 }
 
+// NewCommands returns a new Commands registry.
 func NewCommands() *Commands {
        return &Commands{
                handlers: map[string]CommandHandler{},
@@ -27,7 +36,8 @@ func NewCommands() *Commands {
        }
 }
 
-// Register command. If help string is empty, it will be hidden from Help().
+// Add will register a command. If help string is empty, it will be hidden from
+// Help().
 func (c Commands) Add(command string, help string, handler CommandHandler) {
        c.Lock()
        defer c.Unlock()
@@ -52,9 +62,9 @@ func (c Commands) Alias(command string, alias string) error {
        return nil
 }
 
-// Execute command message, assumes IsCommand was checked.
+// Run executes a command message.
 func (c Commands) Run(channel *Channel, msg CommandMsg) error {
-       if msg.from == nil {
+       if msg.From == nil {
                return ErrNoOwner
        }
 
index 7ee928144f16ebe74a88bbe23bde8e39992bb95f..2248de8dff4d0e492360065b23f44bade0bebffa 100644 (file)
@@ -6,35 +6,35 @@ import (
        "sync"
 )
 
-var ErrIdTaken error = errors.New("id already taken")
-var ErrItemMissing error = errors.New("item does not exist")
+// The error returned when an added id already exists in the set.
+var ErrIdTaken = errors.New("id already taken")
 
-// Unique identifier for an item
-type Id string
+// The error returned when a requested item does not exist in the set.
+var ErrItemMissing = errors.New("item does not exist")
 
-// A prefix for a unique identifier
-type IdPrefix Id
+// Id is a unique identifier for an item.
+type Id string
 
-// An interface for items to store-able in the set
+// Item is an interface for items to store-able in the set
 type Item interface {
        Id() Id
 }
 
-// Set with string lookup
+// Set with string lookup.
 // TODO: Add trie for efficient prefix lookup?
 type Set struct {
        lookup map[Id]Item
        sync.RWMutex
 }
 
-// Create a new set
+// NewSet creates a new set.
 func NewSet() *Set {
        return &Set{
                lookup: map[Id]Item{},
        }
 }
 
-// Remove all items and return the number removed
+// Clear removes all items and returns the number removed.
 func (s *Set) Clear() int {
        s.Lock()
        n := len(s.lookup)
@@ -43,12 +43,12 @@ func (s *Set) Clear() int {
        return n
 }
 
-// Size of the set right now
+// Len returns the size of the set right now.
 func (s *Set) Len() int {
        return len(s.lookup)
 }
 
-// Check if user belongs in this set
+// In checks if an item exists in this set.
 func (s *Set) In(item Item) bool {
        s.RLock()
        _, ok := s.lookup[item.Id()]
@@ -56,7 +56,7 @@ func (s *Set) In(item Item) bool {
        return ok
 }
 
-// Get user by name
+// Get returns an item with the given Id.
 func (s *Set) Get(id Id) (Item, error) {
        s.RLock()
        item, ok := s.lookup[id]
@@ -69,7 +69,7 @@ func (s *Set) Get(id Id) (Item, error) {
        return item, nil
 }
 
-// Add user to set if user does not exist already
+// Add item to this set if it does not exist already.
 func (s *Set) Add(item Item) error {
        s.Lock()
        defer s.Unlock()
@@ -83,7 +83,7 @@ func (s *Set) Add(item Item) error {
        return nil
 }
 
-// Remove user from set
+// Remove item from this set.
 func (s *Set) Remove(item Item) error {
        s.Lock()
        defer s.Unlock()
@@ -96,7 +96,8 @@ func (s *Set) Remove(item Item) error {
        return nil
 }
 
-// Loop over every item while holding a read lock and apply fn
+// Each loops over every item while holding a read lock and applies fn to each
+// element.
 func (s *Set) Each(fn func(item Item)) {
        s.RLock()
        for _, item := range s.lookup {
@@ -105,7 +106,7 @@ func (s *Set) Each(fn func(item Item)) {
        s.RUnlock()
 }
 
-// List users by prefix, case insensitive
+// ListPrefix returns a list of items with a prefix, case insensitive.
 func (s *Set) ListPrefix(prefix string) []Item {
        r := []Item{}
        prefix = strings.ToLower(prefix)
diff --git a/host.go b/host.go
index 2c85ccd102301b226dd05936138f3422cf3a341d..680d553c3ed8d1d4c2e5d006708af9f445e9ac7f 100644 (file)
--- a/host.go
+++ b/host.go
@@ -122,7 +122,7 @@ func (h *Host) AutoCompleteFunction(line string, pos int, key rune) (newLine str
        return
 }
 
-// RefreshPrompt will update the terminal prompt with the latest user name.
+// GetPrompt will render the terminal prompt string based on the user.
 func GetPrompt(user *chat.User) string {
        name := user.Name()
        if user.Config.Theme != nil {