Skip to content

Commit b25d281

Browse files
committed
Update API documentation for 2.0 release
This patch updates the existing API documentation and adds new documentation for types and methods that lack it. Patch by João Reis; reviewed by Bohdan Siryk for CASSGO-78
1 parent 5fd2cdf commit b25d281

File tree

20 files changed

+328
-92
lines changed

20 files changed

+328
-92
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Add way to create HostInfo objects for testing purposes (CASSGO-71)
3636
- Add missing Context methods on Query and Batch (CASSGO-81)
3737
- Update example and test code for 2.0 release (CASSGO-80)
38+
- Add API docs for 2.0 release (CASSGO-78)
3839

3940
### Changed
4041

address_translators.go

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

39+
// AddressTranslatorFunc is a function type that implements AddressTranslator.
3940
type AddressTranslatorFunc func(addr net.IP, port int) (net.IP, int)
4041

4142
func (fn AddressTranslatorFunc) Translate(addr net.IP, port int) (net.IP, int) {

cluster.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ type ClusterConfig struct {
288288
disableControlConn bool
289289
}
290290

291+
// Dialer is the interface that wraps the DialContext method for establishing network connections to Cassandra nodes.
292+
//
293+
// This interface allows customization of how gocql establishes TCP connections, which is useful for:
294+
// connecting through proxies or load balancers, custom TLS configurations, custom timeouts/keep-alive
295+
// settings, service mesh integration, testing with mocked connections, and corporate network routing.
291296
type Dialer interface {
292297
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
293298
}
@@ -357,7 +362,10 @@ func (cfg *ClusterConfig) filterHost(host *HostInfo) bool {
357362
}
358363

359364
var (
360-
ErrNoHosts = errors.New("no hosts provided")
365+
// ErrNoHosts is returned when no hosts are provided to the cluster configuration.
366+
ErrNoHosts = errors.New("no hosts provided")
367+
// ErrNoConnectionsStarted is returned when no connections could be established during session creation.
361368
ErrNoConnectionsStarted = errors.New("no connections were made when creating the session")
362-
ErrHostQueryFailed = errors.New("unable to populate Hosts")
369+
// Deprecated: Never used or returned by the driver.
370+
ErrHostQueryFailed = errors.New("unable to populate Hosts")
363371
)

compressor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
package gocql
2626

27+
// Compressor defines the interface for frame compression and decompression.
28+
// Implementations provide compression algorithms like Snappy and LZ4 that can be used
29+
// to reduce network traffic between the driver and Cassandra nodes.
2730
type Compressor interface {
2831
Name() string
2932

conn.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func JoinHostPort(addr string, port int) string {
6868
return addr
6969
}
7070

71+
// Authenticator handles authentication challenges and responses during connection setup.
7172
type Authenticator interface {
7273
Challenge(req []byte) (resp []byte, auth Authenticator, err error)
7374
Success(data []byte) error
@@ -132,6 +133,7 @@ type SslOptions struct {
132133
EnableHostVerification bool
133134
}
134135

136+
// ConnConfig contains configuration options for establishing connections to Cassandra nodes.
135137
type ConnConfig struct {
136138
ProtoVersion int
137139
CQLVersion string
@@ -150,6 +152,7 @@ type ConnConfig struct {
150152
disableCoalesce bool
151153
}
152154

155+
// ConnErrorHandler handles connection errors and state changes for connections.
153156
type ConnErrorHandler interface {
154157
HandleError(conn *Conn, err error, closed bool)
155158
}

cqltypes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package gocql
2626

27+
// Duration represents a Cassandra duration type, which consists of months, days, and nanoseconds components.
2728
type Duration struct {
2829
Months int32
2930
Days int32

errors.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const (
111111
ErrCodeUnprepared = 0x2500
112112
)
113113

114+
// RequestError represents errors returned by Cassandra server.
114115
type RequestError interface {
115116
Code() int
116117
Message() string
@@ -140,6 +141,8 @@ func (e errorFrame) String() string {
140141
return fmt.Sprintf("[error code=%x message=%q]", e.code, e.message)
141142
}
142143

144+
// RequestErrUnavailable represents an unavailable error returned by Cassandra.
145+
// This error occurs when there are not enough nodes available to fulfill the request.
143146
type RequestErrUnavailable struct {
144147
errorFrame
145148
Consistency Consistency
@@ -151,8 +154,14 @@ func (e *RequestErrUnavailable) String() string {
151154
return fmt.Sprintf("[request_error_unavailable consistency=%s required=%d alive=%d]", e.Consistency, e.Required, e.Alive)
152155
}
153156

157+
// ErrorMap maps node IP addresses to their respective error codes for read/write failure responses.
158+
// Each entry represents a node that failed during the operation, with the key being the node's
159+
// IP address as a string and the value being the specific error code returned by that node.
154160
type ErrorMap map[string]uint16
155161

162+
// RequestErrWriteTimeout represents a write timeout error returned by Cassandra.
163+
// This error occurs when a write request times out after the coordinator
164+
// has successfully written to some replicas but not enough to satisfy the required consistency level.
156165
type RequestErrWriteTimeout struct {
157166
errorFrame
158167
Consistency Consistency
@@ -161,6 +170,8 @@ type RequestErrWriteTimeout struct {
161170
WriteType string
162171
}
163172

173+
// RequestErrWriteFailure represents a write failure error returned by Cassandra.
174+
// This error occurs when a write request fails on one or more replicas.
164175
type RequestErrWriteFailure struct {
165176
errorFrame
166177
Consistency Consistency
@@ -171,10 +182,15 @@ type RequestErrWriteFailure struct {
171182
ErrorMap ErrorMap
172183
}
173184

185+
// RequestErrCDCWriteFailure represents a CDC write failure error returned by Cassandra.
186+
// This error occurs when a write to the Change Data Capture log fails.
174187
type RequestErrCDCWriteFailure struct {
175188
errorFrame
176189
}
177190

191+
// RequestErrReadTimeout represents a read timeout error returned by Cassandra.
192+
// This error occurs when a read request times out after the coordinator
193+
// has received some responses but not enough to satisfy the required consistency level.
178194
type RequestErrReadTimeout struct {
179195
errorFrame
180196
Consistency Consistency
@@ -183,17 +199,23 @@ type RequestErrReadTimeout struct {
183199
DataPresent byte
184200
}
185201

202+
// RequestErrAlreadyExists represents an "already exists" error returned by Cassandra.
203+
// This error occurs when attempting to create a keyspace or table that already exists.
186204
type RequestErrAlreadyExists struct {
187205
errorFrame
188206
Keyspace string
189207
Table string
190208
}
191209

210+
// RequestErrUnprepared represents an "unprepared" error returned by Cassandra.
211+
// This error occurs when a prepared statement is no longer available on the server.
192212
type RequestErrUnprepared struct {
193213
errorFrame
194214
StatementId []byte
195215
}
196216

217+
// RequestErrReadFailure represents a read failure error returned by Cassandra.
218+
// This error occurs when a read request fails on one or more replicas.
197219
type RequestErrReadFailure struct {
198220
errorFrame
199221
Consistency Consistency
@@ -204,6 +226,8 @@ type RequestErrReadFailure struct {
204226
ErrorMap ErrorMap
205227
}
206228

229+
// RequestErrFunctionFailure represents a function failure error returned by Cassandra.
230+
// This error occurs when a user-defined function fails during execution.
207231
type RequestErrFunctionFailure struct {
208232
errorFrame
209233
Keyspace string

frame.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ const (
196196
flagBetaProtocol byte = 0x10
197197
)
198198

199+
// Consistency represents the consistency level for read and write operations.
200+
// Available levels: Any, One, Two, Three, Quorum, All, LocalQuorum, EachQuorum,
201+
// Serial, LocalSerial, LocalOne.
199202
type Consistency uint16
200203

201204
// SerialConsistency is deprecated. Use Consistency instead.

gocqlzap/zap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ import (
2424
gocql "github.com/apache/cassandra-gocql-driver/v2"
2525
)
2626

27+
// DefaultName is the default logger name used when creating a new zap logger.
2728
const DefaultName = "gocql"
2829

30+
// Logger represents a structured logger that integrates zap logging with gocql.
31+
// It extends gocql.StructuredLogger with access to the underlying zap logger.
2932
type Logger interface {
3033
gocql.StructuredLogger
3134
ZapLogger() *zap.Logger

gocqlzerolog/zerolog.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ import (
2424
gocql "github.com/apache/cassandra-gocql-driver/v2"
2525
)
2626

27+
// DefaultName is the default logger name used when creating a new zerolog logger.
2728
const DefaultName = "gocql"
29+
30+
// DefaultNameField is the default field name used to identify the logger in log entries.
2831
const DefaultNameField = "logger"
2932

33+
// Logger represents a structured logger that integrates zerolog logging with gocql.
34+
// It extends gocql.StructuredLogger with access to the underlying zerolog logger.
3035
type Logger interface {
3136
gocql.StructuredLogger
3237
ZerologLogger() zerolog.Logger

0 commit comments

Comments
 (0)