Skip to content

Commit 717061a

Browse files
committed
doc: update inline comments
- replace "tarantool" with "Tarantool" - replace "lua" with "Lua" - remove apostrophes in comments - fixed typos - remove unneeded empty lines that break documentation generation - add a version where new methods or packages were added - remove apostrophes in comment for Connection - add dots to the end of sentences - start sentences with capitalized letter Part of #123
1 parent 0c89df2 commit 717061a

File tree

10 files changed

+161
-129
lines changed

10 files changed

+161
-129
lines changed

client_tools.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"gopkg.in/vmihailenco/msgpack.v2"
55
)
66

7-
// IntKey is utility type for passing integer key to Select*, Update* and Delete*
7+
// IntKey is utility type for passing integer key to Select*, Update* and Delete*.
88
// It serializes to array with single integer element.
99
type IntKey struct {
1010
I int
@@ -16,7 +16,7 @@ func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
1616
return nil
1717
}
1818

19-
// UintKey is utility type for passing unsigned integer key to Select*, Update* and Delete*
19+
// UintKey is utility type for passing unsigned integer key to Select*, Update* and Delete*.
2020
// It serializes to array with single integer element.
2121
type UintKey struct {
2222
I uint
@@ -28,7 +28,7 @@ func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error {
2828
return nil
2929
}
3030

31-
// UintKey is utility type for passing string key to Select*, Update* and Delete*
31+
// UintKey is utility type for passing string key to Select*, Update* and Delete*.
3232
// It serializes to array with single string element.
3333
type StringKey struct {
3434
S string
@@ -40,8 +40,8 @@ func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error {
4040
return nil
4141
}
4242

43-
// IntIntKey is utility type for passing two integer keys to Select*, Update* and Delete*
44-
// It serializes to array with two integer elements
43+
// IntIntKey is utility type for passing two integer keys to Select*, Update* and Delete*.
44+
// It serializes to array with two integer elements.
4545
type IntIntKey struct {
4646
I1, I2 int
4747
}
@@ -53,7 +53,7 @@ func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
5353
return nil
5454
}
5555

56-
// Op - is update operation
56+
// Op - is update operation.
5757
type Op struct {
5858
Op string
5959
Field int

connection.go

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package with implementation of methods and structures for work with
2+
// Tarantool instance.
13
package tarantool
24

35
import (
@@ -27,26 +29,26 @@ type ConnEventKind int
2729
type ConnLogKind int
2830

2931
const (
30-
// Connect signals that connection is established or reestablished
32+
// Connected signals that connection is established or reestablished.
3133
Connected ConnEventKind = iota + 1
32-
// Disconnect signals that connection is broken
34+
// Disconnected signals that connection is broken.
3335
Disconnected
34-
// ReconnectFailed signals that attempt to reconnect has failed
36+
// ReconnectFailed signals that attempt to reconnect has failed.
3537
ReconnectFailed
36-
// Either reconnect attempts exhausted, or explicit Close is called
38+
// Either reconnect attempts exhausted, or explicit Close is called.
3739
Closed
3840

39-
// LogReconnectFailed is logged when reconnect attempt failed
41+
// LogReconnectFailed is logged when reconnect attempt failed.
4042
LogReconnectFailed ConnLogKind = iota + 1
4143
// LogLastReconnectFailed is logged when last reconnect attempt failed,
4244
// connection will be closed after that.
4345
LogLastReconnectFailed
44-
// LogUnexpectedResultId is logged when response with unknown id were received.
46+
// LogUnexpectedResultId is logged when response with unknown id was received.
4547
// Most probably it is due to request timeout.
4648
LogUnexpectedResultId
4749
)
4850

49-
// ConnEvent is sent throw Notify channel specified in Opts
51+
// ConnEvent is sent throw Notify channel specified in Opts.
5052
type ConnEvent struct {
5153
Conn *Connection
5254
Kind ConnEventKind
@@ -80,47 +82,47 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
8082
}
8183
}
8284

83-
// Connection is a handle to Tarantool.
85+
// Connection is a handle with a single connection to a Tarantool instance.
8486
//
8587
// It is created and configured with Connect function, and could not be
8688
// reconfigured later.
8789
//
88-
// It is could be "Connected", "Disconnected", and "Closed".
90+
// Connection could be in three possible states:
8991
//
90-
// When "Connected" it sends queries to Tarantool.
92+
// - In "Connected" state it sends queries to Tarantool.
9193
//
92-
// When "Disconnected" it rejects queries with ClientError{Code: ErrConnectionNotReady}
94+
// - In "Disconnected" state it rejects queries with ClientError{Code:
95+
// ErrConnectionNotReady}
9396
//
94-
// When "Closed" it rejects queries with ClientError{Code: ErrConnectionClosed}
95-
//
96-
// Connection could become "Closed" when Connection.Close() method called,
97-
// or when Tarantool disconnected and Reconnect pause is not specified or
98-
// MaxReconnects is specified and MaxReconnect reconnect attempts already performed.
97+
// - In "Closed" state it rejects queries with ClientError{Code:
98+
// ErrConnectionClosed}. Connection could become "Closed" when
99+
// Connection.Close() method called, or when Tarantool disconnected and
100+
// Reconnect pause is not specified or MaxReconnects is specified and
101+
// MaxReconnect reconnect attempts already performed.
99102
//
100103
// You may perform data manipulation operation by calling its methods:
101104
// Call*, Insert*, Replace*, Update*, Upsert*, Call*, Eval*.
102105
//
103-
// In any method that accepts `space` you my pass either space number or
104-
// space name (in this case it will be looked up in schema). Same is true for `index`.
106+
// In any method that accepts space you my pass either space number or space
107+
// name (in this case it will be looked up in schema). Same is true for index.
105108
//
106-
// ATTENTION: `tuple`, `key`, `ops` and `args` arguments for any method should be
109+
// ATTENTION: tuple, key, ops and args arguments for any method should be
107110
// and array or should serialize to msgpack array.
108111
//
109-
// ATTENTION: `result` argument for *Typed methods should deserialize from
112+
// ATTENTION: result argument for *Typed methods should deserialize from
110113
// msgpack array, cause Tarantool always returns result as an array.
111114
// For all space related methods and Call* (but not Call17*) methods Tarantool
112115
// always returns array of array (array of tuples for space related methods).
113-
// For Eval* and Call17* tarantool always returns array, but does not forces
116+
// For Eval* and Call17* Tarantool always returns array, but does not forces
114117
// array of arrays.
115-
116118
type Connection struct {
117119
addr string
118120
c net.Conn
119121
mutex sync.Mutex
120122
// Schema contains schema loaded on connection.
121123
Schema *Schema
122124
requestId uint32
123-
// Greeting contains first message sent by tarantool
125+
// Greeting contains first message sent by Tarantool.
124126
Greeting *Greeting
125127

126128
shard []connShard
@@ -134,7 +136,7 @@ type Connection struct {
134136
lenbuf [PacketLengthBytes]byte
135137
}
136138

137-
var _ = Connector(&Connection{}) // check compatibility with connector interface
139+
var _ = Connector(&Connection{}) // Check compatibility with connector interface.
138140

139141
type connShard struct {
140142
rmut sync.Mutex
@@ -148,7 +150,7 @@ type connShard struct {
148150
_pad [16]uint64
149151
}
150152

151-
// Greeting is a message sent by tarantool on connect.
153+
// Greeting is a message sent by Tarantool on connect.
152154
type Greeting struct {
153155
Version string
154156
auth string
@@ -157,22 +159,22 @@ type Greeting struct {
157159
// Opts is a way to configure Connection
158160
type Opts struct {
159161
// Timeout is requests timeout.
160-
// Also used to setup net.TCPConn.Set(Read|Write)Deadline
162+
// Also used to setup net.TCPConn.Set(Read|Write)Deadline.
161163
Timeout time.Duration
162164
// Reconnect is a pause between reconnection attempts.
163-
// If specified, then when tarantool is not reachable or disconnected,
165+
// If specified, then when Tarantool is not reachable or disconnected,
164166
// new connect attempt is performed after pause.
165167
// By default, no reconnection attempts are performed,
166168
// so once disconnected, connection becomes Closed.
167169
Reconnect time.Duration
168170
// MaxReconnects is a maximum reconnect attempts.
169171
// After MaxReconnects attempts Connection becomes closed.
170172
MaxReconnects uint
171-
// User name for authorization
173+
// User name for authorization.
172174
User string
173-
// Pass is password for authorization
175+
// Pass is password for authorization.
174176
Pass string
175-
// RateLimit limits number of 'in-fly' request, ie already put into
177+
// RateLimit limits number of 'in-fly' request, i.e. already put into
176178
// requests queue, but not yet answered by server or timeouted.
177179
// It is disabled by default.
178180
// See RLimitAction for possible actions when RateLimit.reached.
@@ -191,42 +193,37 @@ type Opts struct {
191193
// By default it is runtime.GOMAXPROCS(-1) * 4
192194
Concurrency uint32
193195
// SkipSchema disables schema loading. Without disabling schema loading,
194-
// there is no way to create Connection for currently not accessible tarantool.
196+
// there is no way to create Connection for currently not accessible Tarantool.
195197
SkipSchema bool
196198
// Notify is a channel which receives notifications about Connection status
197199
// changes.
198200
Notify chan<- ConnEvent
199-
// Handle is user specified value, that could be retrivied with Handle() method
201+
// Handle is user specified value, that could be retrivied with
202+
// Handle() method.
200203
Handle interface{}
201-
// Logger is user specified logger used for error messages
204+
// Logger is user specified logger used for error messages.
202205
Logger Logger
203206
}
204207

205-
// Connect creates and configures new Connection
208+
// Connect creates and configures a new Connection.
206209
//
207210
// Address could be specified in following ways:
208211
//
209-
// TCP connections:
210-
// - tcp://192.168.1.1:3013
211-
// - tcp://my.host:3013
212-
// - tcp:192.168.1.1:3013
213-
// - tcp:my.host:3013
214-
// - 192.168.1.1:3013
215-
// - my.host:3013
216-
// Unix socket:
217-
// - unix:///abs/path/tnt.sock
218-
// - unix:path/tnt.sock
219-
// - /abs/path/tnt.sock - first '/' indicates unix socket
220-
// - ./rel/path/tnt.sock - first '.' indicates unix socket
221-
// - unix/:path/tnt.sock - 'unix/' acts as a "host" and "/path..." as a port
212+
// - TCP connections (tcp://192.168.1.1:3013, tcp://my.host:3013,
213+
// tcp:192.168.1.1:3013, tcp:my.host:3013, 192.168.1.1:3013, my.host:3013)
214+
//
215+
// - Unix socket, first '/' or '.' indicates Unix socket
216+
// (unix:///abs/path/tnt.sock, unix:path/tnt.sock, /abs/path/tnt.sock,
217+
// ./rel/path/tnt.sock, unix/:path/tnt.sock)
222218
//
223-
// Note:
219+
// Notes:
224220
//
225221
// - If opts.Reconnect is zero (default), then connection either already connected
226222
// or error is returned.
227223
//
228-
// - If opts.Reconnect is non-zero, then error will be returned only if authorization// fails. But if Tarantool is not reachable, then it will attempt to reconnect later
229-
// and will not end attempts on authorization failures.
224+
// - If opts.Reconnect is non-zero, then error will be returned only if authorization
225+
// fails. But if Tarantool is not reachable, then it will make an attempt to reconnect later
226+
// and will not finish to make attempts on authorization failures.
230227
func Connect(addr string, opts Opts) (conn *Connection, err error) {
231228
conn = &Connection{
232229
addr: addr,
@@ -272,10 +269,10 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
272269
return nil, err
273270
} else if ok && (ter.Code == ErrNoSuchUser ||
274271
ter.Code == ErrPasswordMismatch) {
275-
/* reported auth errors immediatly */
272+
// Reported auth errors immediately.
276273
return nil, err
277274
} else {
278-
// without SkipSchema it is useless
275+
// Without SkipSchema it is useless.
279276
go func(conn *Connection) {
280277
conn.mutex.Lock()
281278
defer conn.mutex.Unlock()
@@ -292,7 +289,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
292289
go conn.timeouts()
293290
}
294291

295-
// TODO: reload schema after reconnect
292+
// TODO: reload schema after reconnect.
296293
if !conn.opts.SkipSchema {
297294
if err = conn.loadSchema(); err != nil {
298295
conn.mutex.Lock()
@@ -324,12 +321,12 @@ func (conn *Connection) Close() error {
324321
return conn.closeConnection(err, true)
325322
}
326323

327-
// Addr is configured address of Tarantool socket
324+
// Addr returns a configured address of Tarantool socket.
328325
func (conn *Connection) Addr() string {
329326
return conn.addr
330327
}
331328

332-
// RemoteAddr is address of Tarantool socket
329+
// RemoteAddr returns an address of Tarantool socket.
333330
func (conn *Connection) RemoteAddr() string {
334331
conn.mutex.Lock()
335332
defer conn.mutex.Unlock()
@@ -339,7 +336,7 @@ func (conn *Connection) RemoteAddr() string {
339336
return conn.c.RemoteAddr().String()
340337
}
341338

342-
// LocalAddr is address of outgoing socket
339+
// LocalAddr returns an address of outgoing socket.
343340
func (conn *Connection) LocalAddr() string {
344341
conn.mutex.Lock()
345342
defer conn.mutex.Unlock()
@@ -349,7 +346,7 @@ func (conn *Connection) LocalAddr() string {
349346
return conn.c.LocalAddr().String()
350347
}
351348

352-
// Handle returns user specified handle from Opts
349+
// Handle returns a user-specified handle from Opts.
353350
func (conn *Connection) Handle() interface{} {
354351
return conn.opts.Handle
355352
}
@@ -416,7 +413,7 @@ func (conn *Connection) dial() (err error) {
416413
}
417414
}
418415

419-
// Only if connected and authenticated
416+
// Only if connected and authenticated.
420417
conn.lockShards()
421418
conn.c = connection
422419
atomic.StoreUint32(&conn.state, connConnected)
@@ -873,12 +870,12 @@ func (conn *Connection) nextRequestId() (requestId uint32) {
873870
return atomic.AddUint32(&conn.requestId, 1)
874871
}
875872

876-
// ConfiguredTimeout returns timeout from connection config
873+
// ConfiguredTimeout returns a timeout from connection config.
877874
func (conn *Connection) ConfiguredTimeout() time.Duration {
878875
return conn.opts.Timeout
879876
}
880877

881-
// OverrideSchema sets Schema for the connection
878+
// OverrideSchema sets Schema for the connection.
882879
func (conn *Connection) OverrideSchema(s *Schema) {
883880
if s != nil {
884881
conn.mutex.Lock()

errors.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,38 @@ import (
44
"fmt"
55
)
66

7-
// Error is wrapper around error returned by Tarantool
7+
// Error is wrapper around error returned by Tarantool.
88
type Error struct {
99
Code uint32
1010
Msg string
1111
}
1212

13+
// Error converts an Error to a string.
1314
func (tnterr Error) Error() string {
1415
return fmt.Sprintf("%s (0x%x)", tnterr.Msg, tnterr.Code)
1516
}
1617

17-
// ClientError is connection produced by this client,
18-
// ie connection failures or timeouts.
18+
// ClientError is connection error produced by this client,
19+
// i.e. connection failures or timeouts.
1920
type ClientError struct {
2021
Code uint32
2122
Msg string
2223
}
2324

25+
// Error converts a ClientError to a string.
2426
func (clierr ClientError) Error() string {
2527
return fmt.Sprintf("%s (0x%x)", clierr.Msg, clierr.Code)
2628
}
2729

2830
// Temporary returns true if next attempt to perform request may succeeed.
31+
//
2932
// Currently it returns true when:
30-
// - Connection is not connected at the moment,
31-
// - or request is timeouted,
32-
// - or request is aborted due to rate limit.
33+
//
34+
// - Connection is not connected at the moment
35+
//
36+
// - request is timeouted
37+
//
38+
// - request is aborted due to rate limit
3339
func (clierr ClientError) Temporary() bool {
3440
switch clierr.Code {
3541
case ErrConnectionNotReady, ErrTimeouted, ErrRateLimited:
@@ -39,7 +45,7 @@ func (clierr ClientError) Temporary() bool {
3945
}
4046
}
4147

42-
// Tarantool client error codes
48+
// Tarantool client error codes.
4349
const (
4450
ErrConnectionNotReady = 0x4000 + iota
4551
ErrConnectionClosed = 0x4000 + iota
@@ -48,7 +54,7 @@ const (
4854
ErrRateLimited = 0x4000 + iota
4955
)
5056

51-
// Tarantool server error codes
57+
// Tarantool server error codes.
5258
const (
5359
ErrUnknown = 0 // Unknown error
5460
ErrIllegalParams = 1 // Illegal parameters, %s

0 commit comments

Comments
 (0)