Skip to content

Commit 2ec07af

Browse files
committed
user API doc enhancement
1 parent f3d13d4 commit 2ec07af

File tree

11 files changed

+91
-22
lines changed

11 files changed

+91
-22
lines changed

address_translators.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ type AddressTranslator interface {
3636
Translate(addr net.IP, port int) (net.IP, int)
3737
}
3838

39+
// AddressTranslatorFunc implements AddressTranslator interface.
3940
type AddressTranslatorFunc func(addr net.IP, port int) (net.IP, int)
4041

42+
// Translate translates address and port.
4143
func (fn AddressTranslatorFunc) Translate(addr net.IP, port int) (net.IP, int) {
4244
return fn(addr, port)
4345
}

conn.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ type PasswordAuthenticator struct {
8484
AllowedAuthenticators []string
8585
}
8686

87+
// Challenge creates challenge response for auth handshake.
88+
// Returns an error if authenticator is not approved.
8789
func (p PasswordAuthenticator) Challenge(req []byte) ([]byte, Authenticator, error) {
8890
if !approve(string(req), p.AllowedAuthenticators) {
8991
return nil, nil, fmt.Errorf("unexpected authenticator %q", req)
@@ -96,6 +98,7 @@ func (p PasswordAuthenticator) Challenge(req []byte) ([]byte, Authenticator, err
9698
return resp, nil, nil
9799
}
98100

101+
// Success used in case of success auth handshake.
99102
func (p PasswordAuthenticator) Success(data []byte) error {
100103
return nil
101104
}
@@ -131,6 +134,7 @@ type SslOptions struct {
131134
EnableHostVerification bool
132135
}
133136

137+
// ConnConfig configures connection used by the driver.
134138
type ConnConfig struct {
135139
ProtoVersion int
136140
CQLVersion string
@@ -321,10 +325,15 @@ func (c *Conn) init(ctx context.Context, dialedHost *DialedHost) error {
321325
return nil
322326
}
323327

328+
// Write writes p to the connection.
329+
// It returns the number of bytes written from p (0 <= n <= len(p)) and any error that caused the write to stop
330+
// early.
324331
func (c *Conn) Write(p []byte) (n int, err error) {
325332
return c.w.writeContext(context.Background(), p)
326333
}
327334

335+
// Read reads exactly len(p) bytes from Conn reader into p.
336+
// It returns the number of bytes copied and an error if fewer bytes were read.
328337
func (c *Conn) Read(p []byte) (n int, err error) {
329338
const maxAttempts = 5
330339

@@ -561,6 +570,7 @@ func (c *Conn) close() error {
561570
return c.conn.Close()
562571
}
563572

573+
// Close closes the connection.
564574
func (c *Conn) Close() {
565575
c.closeWithError(nil)
566576
}
@@ -1475,27 +1485,32 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) *Iter {
14751485
}
14761486
}
14771487

1488+
// Pick returns nil if connection is closed.
14781489
func (c *Conn) Pick(qry *Query) *Conn {
14791490
if c.Closed() {
14801491
return nil
14811492
}
14821493
return c
14831494
}
14841495

1496+
// Closed returns true if connection close process for the connection started.
14851497
func (c *Conn) Closed() bool {
14861498
c.mu.Lock()
14871499
defer c.mu.Unlock()
14881500
return c.closed
14891501
}
14901502

1503+
// Address returns address used for the connection.
14911504
func (c *Conn) Address() string {
14921505
return c.addr
14931506
}
14941507

1508+
// AvailableStreams returns the number of the available streams.
14951509
func (c *Conn) AvailableStreams() int {
14961510
return c.streams.Available()
14971511
}
14981512

1513+
// UseKeyspace executes `USE <keyspace>;` query and set keyspace as current.
14991514
func (c *Conn) UseKeyspace(keyspace string) error {
15001515
q := &writeQueryFrame{statement: `USE "` + keyspace + `"`}
15011516
q.params.consistency = c.session.cons

filters.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func AcceptAllFilter() HostFilter {
4747
})
4848
}
4949

50+
// DenyAllFilter will deny all hosts
5051
func DenyAllFilter() HostFilter {
5152
return HostFilterFunc(func(host *HostInfo) bool {
5253
return false
@@ -61,12 +62,6 @@ func DataCenterHostFilter(dataCenter string) HostFilter {
6162
})
6263
}
6364

64-
// Deprecated: Use DataCenterHostFilter instead.
65-
// DataCentreHostFilter is an alias that doesn't use the preferred spelling.
66-
func DataCentreHostFilter(dataCenter string) HostFilter {
67-
return DataCenterHostFilter(dataCenter)
68-
}
69-
7065
// WhiteListHostFilter filters incoming hosts by checking that their address is
7166
// in the initial hosts whitelist.
7267
func WhiteListHostFilter(hosts ...string) HostFilter {

frame.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ func (c *Consistency) UnmarshalText(text []byte) error {
260260
return nil
261261
}
262262

263+
// ParseConsistency returns parsed consistency or panics in case of an error.
263264
func ParseConsistency(s string) Consistency {
264265
var c Consistency
265266
if err := c.UnmarshalText([]byte(strings.ToUpper(s))); err != nil {
@@ -343,6 +344,7 @@ func (f frameHeader) Header() frameHeader {
343344

344345
const defaultBufSize = 128
345346

347+
// ObservedFrameHeader observe header of the frame.
346348
type ObservedFrameHeader struct {
347349
Version protoVersion
348350
Flags byte

helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"gopkg.in/inf.v0"
3636
)
3737

38+
// RowData contains values and column names of a single row.
3839
type RowData struct {
3940
Columns []string
4041
Values []interface{}

host_source.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (c cassVersion) nodeUpDelay() time.Duration {
155155
return 10 * time.Second
156156
}
157157

158+
// HostInfo holds information about the host (e.g. addresses and state).
158159
type HostInfo struct {
159160
// TODO(zariel): reduce locking maybe, not all values will change, but to ensure
160161
// that we are thread safe use a mutex to access all fields.
@@ -181,6 +182,7 @@ type HostInfo struct {
181182
tokens []string
182183
}
183184

185+
// Equal returns true if hosts are equal of if connect addresses of the hosts are equal.
184186
func (h *HostInfo) Equal(host *HostInfo) bool {
185187
if h == host {
186188
// prevent rlock reentry
@@ -190,6 +192,7 @@ func (h *HostInfo) Equal(host *HostInfo) bool {
190192
return h.ConnectAddress().Equal(host.ConnectAddress())
191193
}
192194

195+
// Peer returns hosts peer.
193196
func (h *HostInfo) Peer() net.IP {
194197
h.mu.RLock()
195198
defer h.mu.RUnlock()
@@ -260,92 +263,107 @@ func (h *HostInfo) SetConnectAddress(address net.IP) *HostInfo {
260263
return h
261264
}
262265

266+
// BroadcastAddress returns the broadcast address of the host.
263267
func (h *HostInfo) BroadcastAddress() net.IP {
264268
h.mu.RLock()
265269
defer h.mu.RUnlock()
266270
return h.broadcastAddress
267271
}
268272

273+
// ListenAddress returns the address on which a host listens for incoming connections.
269274
func (h *HostInfo) ListenAddress() net.IP {
270275
h.mu.RLock()
271276
defer h.mu.RUnlock()
272277
return h.listenAddress
273278
}
274279

280+
// RPCAddress returns address on which host listens for RPC requests.
275281
func (h *HostInfo) RPCAddress() net.IP {
276282
h.mu.RLock()
277283
defer h.mu.RUnlock()
278284
return h.rpcAddress
279285
}
280286

287+
// PreferredIP returns the preferred IP of the host.
281288
func (h *HostInfo) PreferredIP() net.IP {
282289
h.mu.RLock()
283290
defer h.mu.RUnlock()
284291
return h.preferredIP
285292
}
286293

294+
// DataCenter returns the name of the host data center.
287295
func (h *HostInfo) DataCenter() string {
288296
h.mu.RLock()
289297
dc := h.dataCenter
290298
h.mu.RUnlock()
291299
return dc
292300
}
293301

302+
// Rack returns the name of the host rack.
294303
func (h *HostInfo) Rack() string {
295304
h.mu.RLock()
296305
rack := h.rack
297306
h.mu.RUnlock()
298307
return rack
299308
}
300309

310+
// HostID returns the host ID.
301311
func (h *HostInfo) HostID() string {
302312
h.mu.RLock()
303313
defer h.mu.RUnlock()
304314
return h.hostId
305315
}
306316

317+
// SetHostID sets the host ID.
307318
func (h *HostInfo) SetHostID(hostID string) {
308319
h.mu.Lock()
309320
defer h.mu.Unlock()
310321
h.hostId = hostID
311322
}
312323

324+
// WorkLoad returns the current workload of the host.
313325
func (h *HostInfo) WorkLoad() string {
314326
h.mu.RLock()
315327
defer h.mu.RUnlock()
316328
return h.workload
317329
}
318330

331+
// Graph returns true if graph mode is enabled for the DSE.
319332
func (h *HostInfo) Graph() bool {
320333
h.mu.RLock()
321334
defer h.mu.RUnlock()
322335
return h.graph
323336
}
324337

338+
// DSEVersion returns the version of DSE instance.
325339
func (h *HostInfo) DSEVersion() string {
326340
h.mu.RLock()
327341
defer h.mu.RUnlock()
328342
return h.dseVersion
329343
}
330344

345+
// Partitioner returns the partitioner kind.
331346
func (h *HostInfo) Partitioner() string {
332347
h.mu.RLock()
333348
defer h.mu.RUnlock()
334349
return h.partitioner
335350
}
336351

352+
// ClusterName returns name of the cluster.
337353
func (h *HostInfo) ClusterName() string {
338354
h.mu.RLock()
339355
defer h.mu.RUnlock()
340356
return h.clusterName
341357
}
342358

359+
// Version returns version of the Cassandra instance.
343360
func (h *HostInfo) Version() cassVersion {
344361
h.mu.RLock()
345362
defer h.mu.RUnlock()
346363
return h.version
347364
}
348365

366+
// State returns state of the node.
349367
func (h *HostInfo) State() nodeState {
350368
h.mu.RLock()
351369
defer h.mu.RUnlock()
@@ -359,12 +377,14 @@ func (h *HostInfo) setState(state nodeState) *HostInfo {
359377
return h
360378
}
361379

380+
// Tokens returns slice of tokens.
362381
func (h *HostInfo) Tokens() []string {
363382
h.mu.RLock()
364383
defer h.mu.RUnlock()
365384
return h.tokens
366385
}
367386

387+
// Port returns port which used for the connection.
368388
func (h *HostInfo) Port() int {
369389
h.mu.RLock()
370390
defer h.mu.RUnlock()
@@ -433,10 +453,13 @@ func (h *HostInfo) update(from *HostInfo) {
433453
}
434454
}
435455

456+
// IsUp return true if the host is not nil and if the host state is node NodeUp.
436457
func (h *HostInfo) IsUp() bool {
437458
return h != nil && h.State() == NodeUp
438459
}
439460

461+
// HostnameAndPort returns a network address of the form "host:port".
462+
// If host contains a colon - "[host]:port" will be returned.
440463
func (h *HostInfo) HostnameAndPort() string {
441464
h.mu.Lock()
442465
defer h.mu.Unlock()
@@ -447,6 +470,8 @@ func (h *HostInfo) HostnameAndPort() string {
447470
return net.JoinHostPort(h.hostname, strconv.Itoa(h.port))
448471
}
449472

473+
// ConnectAddressAndPort returns a network address of the form "host:port".
474+
// If connect address contains a colon - "[host]:port" will be returned.
450475
func (h *HostInfo) ConnectAddressAndPort() string {
451476
h.mu.Lock()
452477
defer h.mu.Unlock()

marshal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ type TypeInfo interface {
24692469
NewWithError() (interface{}, error)
24702470
}
24712471

2472+
// NativeType describes a Cassandra native types
24722473
type NativeType struct {
24732474
proto byte
24742475
typ Type
@@ -2487,14 +2488,17 @@ func (t NativeType) NewWithError() (interface{}, error) {
24872488
return reflect.New(typ).Interface(), nil
24882489
}
24892490

2491+
// Type returns identifier of a Cassandra internal datatype.
24902492
func (s NativeType) Type() Type {
24912493
return s.typ
24922494
}
24932495

2496+
// Version returns native protocol version of a type.
24942497
func (s NativeType) Version() byte {
24952498
return s.proto
24962499
}
24972500

2501+
// Custom returns the name of custom class.
24982502
func (s NativeType) Custom() string {
24992503
return s.custom
25002504
}
@@ -2508,6 +2512,7 @@ func (s NativeType) String() string {
25082512
}
25092513
}
25102514

2515+
// CollectionType describes a Cassandra collection types.
25112516
type CollectionType struct {
25122517
NativeType
25132518
Key TypeInfo // only used for TypeMap
@@ -2535,6 +2540,7 @@ func (c CollectionType) String() string {
25352540
}
25362541
}
25372542

2543+
// TupleTypeInfo describes a Cassandra tuple types.
25382544
type TupleTypeInfo struct {
25392545
NativeType
25402546
Elems []TypeInfo
@@ -2564,6 +2570,7 @@ type UDTField struct {
25642570
Type TypeInfo
25652571
}
25662572

2573+
// UDTTypeInfo describes a Cassandra UDT types.
25672574
type UDTTypeInfo struct {
25682575
NativeType
25692576
KeySpace string

metadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ type MaterializedViewMetadata struct {
136136
baseTableName string
137137
}
138138

139+
// UserTypeMetadata holds the metadata for user types.
139140
type UserTypeMetadata struct {
140141
Keyspace string
141142
Name string

0 commit comments

Comments
 (0)