Skip to content

Commit 511be04

Browse files
committed
chg: golint
1 parent b718b50 commit 511be04

13 files changed

+46
-35
lines changed

clientproxy.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package signalr
22

3+
//ClientProxy allows the hub to send messages to one or more of its clients
34
type ClientProxy interface {
45
Send(target string, args ...interface{})
56
}

groupmanager.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package signalr
22

3+
//GroupManager manages the client groups of the hub
34
type GroupManager interface {
45
AddToGroup(groupName string, connectionID string)
56
RemoveFromGroup(groupName string, connectionID string)

hub.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
package signalr
22

3+
// HubInterface is a hubs interface
34
type HubInterface interface {
45
Initialize(hubContext HubContext)
56
OnConnected(connectionID string)
67
OnDisconnected(connectionID string)
78
}
89

10+
// Hub is a base class for hubs
911
type Hub struct {
1012
context HubContext
1113
}
1214

15+
// Initialize initializes a hub with a HubContext
1316
func (h *Hub) Initialize(ctx HubContext) {
1417
h.context = ctx
1518
}
1619

20+
// Clients returns the clients of this hub
1721
func (h *Hub) Clients() HubClients {
1822
return h.context.Clients()
1923
}
2024

25+
// Groups returns the client groups of this hub
2126
func (h *Hub) Groups() GroupManager {
2227
return h.context.Groups()
2328
}
2429

30+
// OnConnected is called when the hub is connected
2531
func (h *Hub) OnConnected(string) {}
2632

33+
//OnDisconnected is called when the hub is disconnected
2734
func (h *Hub) OnDisconnected(string) {}

hubclients.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package signalr
22

3+
//HubClients gives the hub access to various client groups
34
type HubClients interface {
45
All() ClientProxy
56
Client(connectionID string) ClientProxy

hubconnection.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
"sync/atomic"
77
)
88

9+
//Connection describes a connection between signalR client and server
10+
type Connection interface {
11+
io.Reader
12+
io.Writer
13+
ConnectionID() string
14+
}
15+
916
type hubConnection interface {
1017
Start()
1118
IsConnected() bool
@@ -18,12 +25,6 @@ type hubConnection interface {
1825
Ping()
1926
}
2027

21-
type Connection interface {
22-
io.Reader
23-
io.Writer
24-
ConnectionId() string
25-
}
26-
2728
func newHubConnection(connection Connection, protocol HubProtocol) hubConnection {
2829
return &defaultHubConnection{
2930
Protocol: protocol,
@@ -57,7 +58,7 @@ func (c *defaultHubConnection) Close(error string) {
5758
}
5859

5960
func (c *defaultHubConnection) GetConnectionID() string {
60-
return c.Connection.ConnectionId()
61+
return c.Connection.ConnectionID()
6162
}
6263

6364
func (c *defaultHubConnection) SendInvocation(target string, args []interface{}) {
@@ -87,10 +88,10 @@ func (c *defaultHubConnection) Receive() (interface{}, error) {
8788
// Partial message, need more data
8889
// ReadMessage read data out of the buf, so its gone there: refill
8990
buf.Write(data[:n])
90-
if n, err = c.Connection.Read(data); err != nil {
91-
return nil, err
92-
} else {
91+
if n, err = c.Connection.Read(data); err == nil {
9392
buf.Write(data[:n])
93+
} else {
94+
return nil, err
9495
}
9596
} else {
9697
return message, err

hubcontext.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package signalr
22

3+
//HubContext holds the clients and groups connected to the hub
34
type HubContext interface {
45
Clients() HubClients
56
Groups() GroupManager

hublifetimemanager.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package signalr
22

33
import "sync"
44

5+
//HubLifetimeManager manages the lifetime of a hub
56
type HubLifetimeManager interface {
67
OnConnected(conn hubConnection)
78
OnDisconnected(conn hubConnection)

jsonhubprotocol.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
)
99

10-
type JsonHubProtocol struct {
10+
type jsonHubProtocol struct {
1111
}
1212

1313
// Protocol specific message for correct unmarshaling of Arguments
@@ -19,11 +19,11 @@ type jsonInvocationMessage struct {
1919
StreamIds []string `json:"streamIds,omitempty"`
2020
}
2121

22-
func (j *JsonHubProtocol) UnmarshalArgument(argument interface{}, value interface{}) error {
22+
func (j *jsonHubProtocol) UnmarshalArgument(argument interface{}, value interface{}) error {
2323
return json.Unmarshal(argument.(json.RawMessage), value)
2424
}
2525

26-
func (j *JsonHubProtocol) ReadMessage(buf *bytes.Buffer) (interface{}, bool, error) {
26+
func (j *jsonHubProtocol) ReadMessage(buf *bytes.Buffer) (interface{}, bool, error) {
2727
data, err := parseTextMessageFormat(buf)
2828
switch {
2929
case err == io.EOF:
@@ -86,7 +86,7 @@ func parseTextMessageFormat(buf *bytes.Buffer) ([]byte, error) {
8686
return data[0 : len(data)-1], err
8787
}
8888

89-
func (j *JsonHubProtocol) WriteMessage(message interface{}, writer io.Writer) error {
89+
func (j *jsonHubProtocol) WriteMessage(message interface{}, writer io.Writer) error {
9090

9191
// TODO: Reduce the amount of copies
9292

server.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import (
1111
"time"
1212
)
1313

14-
type Server struct {
14+
type server struct {
1515
hub HubInterface
1616
lifetimeManager HubLifetimeManager
17-
defaultHubClients defaultHubClients
17+
defaultHubClients HubClients
1818
groupManager GroupManager
1919
}
2020

21-
func NewServer(hub HubInterface) *Server {
21+
func newServer(hub HubInterface) *server {
2222
lifetimeManager := defaultHubLifetimeManager{}
23-
return &Server{
23+
return &server{
2424
hub: hub,
2525
lifetimeManager: &lifetimeManager,
26-
defaultHubClients: defaultHubClients{
26+
defaultHubClients: &defaultHubClients{
2727
lifetimeManager: &lifetimeManager,
2828
allCache: allClientProxy{lifetimeManager: &lifetimeManager},
2929
},
@@ -33,7 +33,7 @@ func NewServer(hub HubInterface) *Server {
3333
}
3434
}
3535

36-
func (s *Server) messageLoop(conn Connection) {
36+
func (s *server) messageLoop(conn Connection) {
3737
if protocol, err := processHandshake(conn); err != nil {
3838
fmt.Println(err)
3939
} else {
@@ -65,7 +65,7 @@ func (s *Server) messageLoop(conn Connection) {
6565
// argument build failed
6666
hubConn.Completion(invocation.InvocationID, nil, err.Error())
6767
} else if clientStreaming {
68-
// let the receiving method run idependently
68+
// let the receiving method run independently
6969
go func() {
7070
defer func() {
7171
if err := recover(); err != nil {
@@ -124,10 +124,10 @@ type hubInfo struct {
124124
methods map[string]reflect.Value
125125
}
126126

127-
func (s *Server) newHubInfo() *hubInfo {
127+
func (s *server) newHubInfo() *hubInfo {
128128

129129
s.hub.Initialize(&defaultHubContext{
130-
clients: &s.defaultHubClients,
130+
clients: s.defaultHubClients,
131131
groups: s.groupManager,
132132
})
133133

@@ -286,7 +286,7 @@ func processHandshake(conn Connection) (HubProtocol, error) {
286286
}
287287

288288
var protocolMap = map[string]HubProtocol{
289-
"json": &JsonHubProtocol{},
289+
"json": &jsonHubProtocol{},
290290
}
291291

292292
type availableTransport struct {

signalr_suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestSignalr(t *testing.T) {
1313
}
1414

1515
func connect(hubProto HubInterface) *testingConnection {
16-
server := NewServer(hubProto)
16+
server := newServer(hubProto)
1717
conn := newTestingConnection()
1818
go server.messageLoop(conn)
1919
return conn

testingconnection_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type testingConnection struct {
1414
received chan interface{}
1515
}
1616

17-
func (t *testingConnection) ConnectionId() string {
17+
func (t *testingConnection) ConnectionID() string {
1818
return "test"
1919
}
2020

@@ -75,10 +75,10 @@ func (t *testingConnection) clientReceive() (string, error) {
7575
for {
7676
if message, err := buf.ReadString(30); err != nil {
7777
buf.Write(data[:n])
78-
if n, err = t.cliReader.Read(data); err != nil {
79-
return "", err
80-
} else {
78+
if n, err = t.cliReader.Read(data); err == nil {
8179
buf.Write(data[:n])
80+
} else{
81+
return "", err
8282
}
8383
} else {
8484
return message[:len(message)-1], nil

websocketServer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// MapHub used to register a SignalR Hub with the specified ServeMux
1313
func MapHub(mux *http.ServeMux, path string, hub HubInterface) {
1414
mux.HandleFunc(fmt.Sprintf("%s/negotiate", path), negotiateHandler)
15-
server := NewServer(hub)
15+
server := newServer(hub)
1616
mux.Handle(path, websocket.Handler(func(ws *websocket.Conn) {
1717
connectionID := ws.Request().URL.Query().Get("id")
1818
if len(connectionID) == 0 {

websocketconnection.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type webSocketConnection struct {
1111
connectionID string
1212
}
1313

14-
func (w *webSocketConnection) ConnectionId() string {
14+
func (w *webSocketConnection) ConnectionID() string {
1515
return w.connectionID
1616
}
1717

@@ -24,11 +24,9 @@ func (w *webSocketConnection) Read(p []byte) (n int, err error) {
2424
var data []byte
2525
if err = websocket.Message.Receive(w.ws, &data); err != nil {
2626
return 0, err
27-
} else {
28-
w.r = bytes.NewReader(data)
29-
return w.r.Read(p)
3027
}
31-
} else {
28+
w.r = bytes.NewReader(data)
3229
return w.r.Read(p)
3330
}
31+
return w.r.Read(p)
3432
}

0 commit comments

Comments
 (0)