diff --git a/client.go b/client.go index 140db3b02..19b0aff50 100644 --- a/client.go +++ b/client.go @@ -86,11 +86,11 @@ type joinWorkspaceResult struct { SessionNumber int `json:"sessionNumber"` } -func (client *Client) joinWorkspace(ctx context.Context, rpc *rpcClient) (*joinWorkspaceResult, error) { +func (c *Client) joinWorkspace(ctx context.Context, rpc *rpcClient) (*joinWorkspaceResult, error) { args := joinWorkspaceArgs{ - ID: client.connection.SessionID, + ID: c.connection.SessionID, ConnectionMode: "local", - JoiningUserSessionToken: client.connection.SessionToken, + JoiningUserSessionToken: c.connection.SessionToken, ClientCapabilities: clientCapabilities{ IsNonInteractive: false, }, @@ -104,14 +104,14 @@ func (client *Client) joinWorkspace(ctx context.Context, rpc *rpcClient) (*joinW return &result, nil } -func (session *Session) openStreamingChannel(ctx context.Context, streamName, condition string) (ssh.Channel, error) { +func (s *Session) openStreamingChannel(ctx context.Context, streamName, condition string) (ssh.Channel, error) { args := getStreamArgs{streamName, condition} var streamID string - if err := session.rpc.do(ctx, "streamManager.getStream", args, &streamID); err != nil { + if err := s.rpc.do(ctx, "streamManager.getStream", args, &streamID); err != nil { return nil, fmt.Errorf("error getting stream id: %v", err) } - channel, reqs, err := session.ssh.conn.OpenChannel("session", nil) + channel, reqs, err := s.ssh.conn.OpenChannel("session", nil) if err != nil { return nil, fmt.Errorf("error opening ssh channel for transport: %v", err) } diff --git a/port_forwarder_test.go b/port_forwarder_test.go index 6af5c7e70..44ef59fe0 100644 --- a/port_forwarder_test.go +++ b/port_forwarder_test.go @@ -46,7 +46,8 @@ func TestPortForwarderStart(t *testing.T) { } defer testServer.Close() - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() pf := NewPortForwarder(session, 8000) done := make(chan error) diff --git a/rpc_test.go b/rpc_test.go index d16b32a4f..7543152d1 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -15,7 +15,8 @@ func TestRPCHandlerEvents(t *testing.T) { time.Sleep(1 * time.Second) rpcHandler.Handle(context.Background(), nil, &jsonrpc2.Request{Method: "somethingHappened"}) }() - ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second)) + ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second)) + defer cancel() select { case event := <-eventCh: if event.Method != "somethingHappened" { diff --git a/session.go b/session.go index b1a175df3..d13bba9f1 100644 --- a/session.go +++ b/session.go @@ -3,7 +3,6 @@ package liveshare import ( "context" "fmt" - "strconv" ) // A Session represents the session between a connected Live Share client and server. @@ -25,6 +24,8 @@ type Port struct { IsPublic bool `json:"isPublic"` IsTCPServerConnectionEstablished bool `json:"isTCPServerConnectionEstablished"` HasTSLHandshakePassed bool `json:"hasTSLHandshakePassed"` + // ^^^ + // TODO(adonovan): fix possible typo in field name, and audit others. } // StartSharing tells the liveshare host to start sharing the port from the container @@ -33,7 +34,7 @@ func (s *Session) StartSharing(ctx context.Context, protocol string, port int) e var response Port if err := s.rpc.do(ctx, "serverSharing.startSharing", []interface{}{ - port, protocol, fmt.Sprintf("http://localhost:%s", strconv.Itoa(port)), + port, protocol, fmt.Sprintf("http://localhost:%d", port), }, &response); err != nil { return err }