lint: don't use global `log`

users can change the logger now via gavalink.Log
This commit is contained in:
Christopher F 2018-08-23 18:15:39 -04:00
parent 566c1b0777
commit 35bfb14058
2 changed files with 16 additions and 8 deletions

View File

@ -2,8 +2,17 @@ package gavalink
import (
"errors"
"log"
"os"
)
// Log sets the log.Logger gavalink will write to
var Log *log.Logger
func init() {
Log = log.New(os.Stdout, "(gavalink)", 0)
}
// Lavalink manages a connection to Lavalink Nodes
type Lavalink struct {
shards string
@ -52,7 +61,7 @@ func (lavalink *Lavalink) AddNodes(nodeConfigs ...NodeConfig) error {
}
// RemoveNode removes a node from the manager
func (lavalink *Lavalink) RemoveNode(node *Node) error {
func (lavalink *Lavalink) removeNode(node *Node) error {
idx := -1
for i, n := range lavalink.nodes {
if n == *node {

13
node.go
View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strconv"
@ -56,7 +55,7 @@ func (node *Node) open() error {
node.wsConn = ws
go node.listen()
log.Println("node", node.config.WebSocket, "opened")
Log.Println("node", node.config.WebSocket, "opened")
return nil
}
@ -73,20 +72,20 @@ func (node *Node) listen() {
for {
msgType, msg, err := node.wsConn.ReadMessage()
if err != nil {
log.Println(err)
Log.Println(err)
// try to reconnect
oerr := node.open()
if oerr != nil {
log.Println("node", node.config.WebSocket, "failed and could not reconnect, destroying.", err, oerr)
node.manager.RemoveNode(node)
Log.Println("node", node.config.WebSocket, "failed and could not reconnect, destroying.", err, oerr)
node.manager.removeNode(node)
return
}
log.Println("node", node.config.WebSocket, "reconnected")
Log.Println("node", node.config.WebSocket, "reconnected")
return
}
err = node.onEvent(msgType, msg)
// TODO: better error handling
log.Println(err)
Log.Println(err)
}
}