Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 2efc360

Browse files
Use a regular logger, add mod support
1 parent ddf1bd0 commit 2efc360

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ type Client struct {
3333
// poll listens for responses/events.
3434
// This function blocks until Disconnect is called.
3535
func (c *Client) poll() {
36-
logger.Debug("started polling")
36+
Logger.Println("started polling")
3737

3838
for c.connected {
3939
m := make(map[string]interface{})
4040
if err := c.conn.ReadJSON(&m); err != nil {
4141
if !c.connected {
4242
return
4343
}
44-
logger.Warning("read from WS:", err)
44+
Logger.Println("read from WS:", err)
4545
continue
4646
}
4747

@@ -80,12 +80,12 @@ func mapToStruct(data map[string]interface{}, dest interface{}) error {
8080
Result: dest,
8181
})
8282
if err != nil {
83-
logger.Warning("initializing decoder:", err)
83+
Logger.Println("initializing decoder:", err)
8484
return err
8585
}
8686
if err = decoder.Decode(data); err != nil {
87-
logger.Warningf("unmarshalling map -> %T: %v", dest, err)
88-
logger.Debugf("input: %#v\n", data)
87+
Logger.Printf("unmarshalling map -> %T: %v", dest, err)
88+
Logger.Printf("input: %#v\n", data)
8989
return err
9090
}
9191
return nil

client_connection.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func (c *Client) Connect() error {
3333
}
3434

3535
if !respGAR.AuthRequired {
36-
logger.Info("logged in (no authentication required)")
36+
Logger.Println("logged in (no authentication required)")
3737
c.connected = true
3838
go c.poll()
3939
return nil
4040
}
4141

4242
auth := getAuth(c.Password, respGAR.Salt, respGAR.Challenge)
43-
logger.Debug("auth:", auth)
43+
Logger.Println("auth:", auth)
4444

4545
reqA := NewAuthenticateRequest(auth)
4646
if err = c.conn.WriteJSON(reqA); err != nil {
@@ -55,7 +55,7 @@ func (c *Client) Connect() error {
5555
return errors.New(respA.Error())
5656
}
5757

58-
logger.Info("logged in (authentication successful)")
58+
Logger.Println("logged in (authentication successful)")
5959
c.connected = true
6060
go c.poll()
6161
return nil
@@ -73,7 +73,7 @@ func (c *Client) Disconnect() error {
7373
// connectWS opens the WebSocket connection.
7474
func connectWS(host string, port int) (*websocket.Conn, error) {
7575
url := fmt.Sprintf("ws://%s:%d", host, port)
76-
logger.Debug("connecting to", url)
76+
Logger.Println("connecting to", url)
7777
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
7878
if err != nil {
7979
return nil, err

client_events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (c *Client) handleEvent(m map[string]interface{}) {
2727

2828
eventFn, ok := eventMap[t]
2929
if !ok {
30-
logger.Warning("unknown event type:", m["update-type"])
30+
Logger.Println("unknown event type:", m["update-type"])
3131
return
3232
}
3333
event := eventFn()
@@ -38,7 +38,7 @@ func (c *Client) handleEvent(m map[string]interface{}) {
3838
}
3939

4040
if err := mapToStruct(m, event); err != nil {
41-
logger.Warning("event handler failed:", err)
41+
Logger.Println("event handler failed:", err)
4242
return
4343
}
4444

client_requests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (c *Client) sendRequest(req Request) (chan map[string]interface{}, error) {
2323
if err := c.conn.WriteJSON(req); err != nil {
2424
return nil, err
2525
}
26-
logger.Debug("sent request", req.ID())
26+
Logger.Println("sent request", req.ID())
2727
go func() { future <- c.receive(req.ID()) }()
2828
return future, nil
2929
}
@@ -33,7 +33,7 @@ func (c *Client) receive(id string) map[string]interface{} {
3333
for {
3434
resp := <-c.respQ
3535
if resp["message-id"] == id {
36-
logger.Debug("received response", resp["message-id"])
36+
Logger.Println("received response", resp["message-id"])
3737
return resp
3838
}
3939
c.respQ <- resp

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module github.com/christopher-dG/go-obs-websocket
2+
3+
require (
4+
github.com/gorilla/websocket v1.4.0
5+
github.com/mitchellh/mapstructure v1.1.2
6+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
2+
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
3+
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
4+
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=

logger.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package obsws
22

3-
import "github.com/op/go-logging"
3+
import (
4+
"log"
5+
"os"
6+
)
47

5-
var logger = logging.MustGetLogger("obsws")
8+
var Logger = log.New(os.Stdout, "[obsws] ", log.LstdFlags)

0 commit comments

Comments
 (0)