Skip to content

Commit 8535762

Browse files
committed
all: add godoc comment and nolint pragma
1 parent 13accb9 commit 8535762

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const (
3434
// CodeContentModified is the state change that invalidates the result of a request in execution.
3535
CodeContentModified Code = -32801
3636

37-
codeServerErrorStart Code = -32099
38-
codeServerErrorEnd Code = -32000
37+
codeServerErrorStart Code = -32099 //nolint:deadcode,varcheck
38+
codeServerErrorEnd Code = -32000 //nolint:deadcode,varcheck
3939
)
4040

4141
// Error represents a jsonrpc2 error.

jsonrpc2.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010
)
1111

12+
// Interface represents an interface for issuing requests that speak the JSON-RPC 2 protocol.
1213
type Interface interface {
1314
Call(ctx context.Context, method string, params, result interface{}) error
1415

@@ -40,26 +41,31 @@ type Canceler func(context.Context, *Conn, *Request)
4041
// Conn is a JSON RPC 2 client server connection.
4142
// Conn is bidirectional; it does not have a designated server or client end.
4243
type Conn struct {
43-
handle Handler
44-
cancel Canceler
45-
stream Stream
46-
done chan struct{}
47-
err error
48-
seq int64 // must only be accessed using atomic operations
49-
pendingMu sync.Mutex // protects the pending map
50-
pending map[ID]chan *Response
44+
handle Handler
45+
cancel Canceler
46+
stream Stream
47+
done chan struct{}
48+
err error
49+
//nolint:structcheck
50+
seq int64 // must only be accessed using atomic operations
51+
//nolint:structcheck
52+
pendingMu sync.Mutex // protects the pending map
53+
pending map[ID]chan *Response //nolint:structcheck
5154
}
5255

5356
var _ Interface = (*Conn)(nil)
5457

58+
// Options represents a functional options.
5559
type Options func(*Conn)
5660

61+
// WithHandler apply custom hander to Conn.
5762
func WithHandler(h Handler) Options {
5863
return func(c *Conn) {
5964
c.handle = h
6065
}
6166
}
6267

68+
// WithCanceler apply custom canceler to Conn.
6369
func WithCanceler(cancel Canceler) Options {
6470
return func(c *Conn) {
6571
c.cancel = cancel
@@ -101,14 +107,19 @@ func NewConn(ctx context.Context, s Stream, options ...Options) *Conn {
101107

102108
func (c *Conn) run(ctx context.Context) error { return nil }
103109

110+
// Call sends a request over the connection and then waits for a response.
104111
func (c *Conn) Call(ctx context.Context, method string, params, result interface{}) error { return nil }
105112

113+
// Reply sends a reply to the given request.
106114
func (c *Conn) Reply(ctx context.Context, req *Request, result interface{}, err error) error {
107115
return nil
108116
}
109117

118+
// Notify is called to send a notification request over the connection.
110119
func (c *Conn) Notify(ctx context.Context, method string, params interface{}) error { return nil }
111120

121+
// Cancel cancels a pending Call on the server side.
112122
func (c *Conn) Cancel(id ID) {}
113123

124+
// Wait blocks until the connection is terminated, and returns any error that cause the termination.
114125
func (c *Conn) Wait(ctx context.Context) error { return nil }

stream.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type stream struct {
3030
sync.Mutex
3131
}
3232

33+
// NewStream returns the new Stream.
3334
func NewStream(in io.Reader, out io.Writer) Stream {
3435
return &stream{
3536
in: bufio.NewReader(in),

0 commit comments

Comments
 (0)