Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNero committed May 10, 2021
1 parent b196243 commit 843775b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions examples/gowebsocket/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"log"
"github.com/sacOO7/gowebsocket"
"log"
"os"
"os/signal"
)
Expand All @@ -11,12 +11,12 @@ func main() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

socket := gowebsocket.New("ws://echo.websocket.org/");
socket := gowebsocket.New("ws://echo.websocket.org/")
socket.ConnectionOptions = gowebsocket.ConnectionOptions{
//Proxy: gowebsocket.BuildProxy("http://example.com"),
UseSSL: false,
UseCompression: false,
Subprotocols: [] string{"chat", "superchat"},
Subprotocols: []string{"chat", "superchat"},
}

socket.RequestHeader.Set("Accept-Encoding", "gzip, deflate, sdch")
Expand All @@ -26,24 +26,24 @@ func main() {

socket.OnConnectError = func(err error, socket gowebsocket.Socket) {
log.Fatal("Recieved connect error ", err)
};
}
socket.OnConnected = func(socket gowebsocket.Socket) {
log.Println("Connected to server");
};
log.Println("Connected to server")
}
socket.OnTextMessage = func(message string, socket gowebsocket.Socket) {
log.Println("Recieved message " + message)
};
}
socket.OnPingReceived = func(data string, socket gowebsocket.Socket) {
log.Println("Recieved ping " + data)
};
}
socket.OnDisconnected = func(err error, socket gowebsocket.Socket) {
log.Println("Disconnected from server ")
return
};
}
socket.Connect()

i := 0
for (i < 10) {
for i < 10 {
socket.SendText("This is my sample test message")
i++
}
Expand Down
24 changes: 12 additions & 12 deletions gowebsocket.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package gowebsocket

import (
"crypto/tls"
"errors"
"github.com/gorilla/websocket"
"github.com/sacOO7/go-logger"
"net/http"
"errors"
"crypto/tls"
"net/url"
"sync"
"github.com/sacOO7/go-logger"
"reflect"
"sync"
"time"
)

Expand All @@ -22,7 +22,7 @@ func (socket Socket) EnableLogging() {
}

func (socket Socket) GetLogger() logging.Logger {
return logger;
return logger
}

type Socket struct {
Expand All @@ -33,7 +33,7 @@ type Socket struct {
RequestHeader http.Header
OnConnected func(socket Socket)
OnTextMessage func(message string, socket Socket)
OnBinaryMessage func(data [] byte, socket Socket)
OnBinaryMessage func(data []byte, socket Socket)
OnConnectError func(err error, socket Socket)
OnDisconnected func(err error, socket Socket)
OnPingReceived func(data string, socket Socket)
Expand All @@ -48,7 +48,7 @@ type ConnectionOptions struct {
UseCompression bool
UseSSL bool
Proxy func(*http.Request) (*url.URL, error)
Subprotocols [] string
Subprotocols []string
}

// todo Yet to be done
Expand All @@ -57,7 +57,7 @@ type ReconnectionOptions struct {

func New(url string) Socket {
return Socket{
Url: url,
Url: url,
RequestHeader: http.Header{},
ConnectionOptions: ConnectionOptions{
UseCompression: false,
Expand All @@ -78,7 +78,7 @@ func (socket *Socket) setConnectionOptions() {
}

func (socket *Socket) Connect() {
var err error;
var err error
var resp *http.Response
socket.setConnectionOptions()

Expand Down Expand Up @@ -163,22 +163,22 @@ func (socket *Socket) Connect() {
}

func (socket *Socket) SendText(message string) {
err := socket.send(websocket.TextMessage, [] byte (message))
err := socket.send(websocket.TextMessage, []byte(message))
if err != nil {
logger.Error.Println("write:", err)
return
}
}

func (socket *Socket) SendBinary(data [] byte) {
func (socket *Socket) SendBinary(data []byte) {
err := socket.send(websocket.BinaryMessage, data)
if err != nil {
logger.Error.Println("write:", err)
return
}
}

func (socket *Socket) send(messageType int, data [] byte) error {
func (socket *Socket) send(messageType int, data []byte) error {
socket.sendMu.Lock()
err := socket.Conn.WriteMessage(messageType, data)
socket.sendMu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gowebsocket

import (
"log"
"net/http"
"net/url"
"log"
)

func BuildProxy(Url string) func(*http.Request) (*url.URL, error) {
Expand Down

0 comments on commit 843775b

Please sign in to comment.