Skip to content

Commit 171d258

Browse files
committed
user API doc enhancement
1 parent 65e2caf commit 171d258

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.
@@ -193,6 +194,7 @@ func newHostInfo(addr net.IP, port int) (*HostInfo, error) {
193194
return host, nil
194195
}
195196

197+
// Equal returns true if hosts are equal of if connect addresses of the hosts are equal.
196198
func (h *HostInfo) Equal(host *HostInfo) bool {
197199
if h == host {
198200
// prevent rlock reentry
@@ -202,6 +204,7 @@ func (h *HostInfo) Equal(host *HostInfo) bool {
202204
return h.ConnectAddress().Equal(host.ConnectAddress())
203205
}
204206

207+
// Peer returns hosts peer.
205208
func (h *HostInfo) Peer() net.IP {
206209
h.mu.RLock()
207210
defer h.mu.RUnlock()
@@ -259,92 +262,107 @@ func (h *HostInfo) ConnectAddress() net.IP {
259262
return addr
260263
}
261264

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

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

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

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

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

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

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

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

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

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

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

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

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

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

365+
// State returns state of the node.
348366
func (h *HostInfo) State() nodeState {
349367
h.mu.RLock()
350368
defer h.mu.RUnlock()
@@ -358,12 +376,14 @@ func (h *HostInfo) setState(state nodeState) *HostInfo {
358376
return h
359377
}
360378

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

386+
// Port returns port which used for the connection.
367387
func (h *HostInfo) Port() int {
368388
h.mu.RLock()
369389
defer h.mu.RUnlock()
@@ -432,10 +452,13 @@ func (h *HostInfo) update(from *HostInfo) {
432452
}
433453
}
434454

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

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

472+
// ConnectAddressAndPort returns a network address of the form "host:port".
473+
// If connect address contains a colon - "[host]:port" will be returned.
449474
func (h *HostInfo) ConnectAddressAndPort() string {
450475
h.mu.Lock()
451476
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)