lint: don't use global `log`
users can change the logger now via gavalink.Log
This commit is contained in:
parent
566c1b0777
commit
35bfb14058
11
lavalink.go
11
lavalink.go
|
@ -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
13
node.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue