Skip to content

Commit db18072

Browse files
committed
add API docs for public api elements that don't have them
1 parent a9bfe80 commit db18072

File tree

12 files changed

+121
-10
lines changed

12 files changed

+121
-10
lines changed

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
)

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

logger.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func writeLogMsg(buf *bytes.Buffer, prefix string, msg string, fields []LogField
183183
writeFields(buf, fields)
184184
}
185185

186+
// LogLevel represents the level of logging to be performed.
187+
// Higher values indicate more verbose logging.
188+
// Available levels: LogLevelDebug, LogLevelInfo, LogLevelWarn, LogLevelError, LogLevelNone.
186189
type LogLevel int
187190

188191
const (
@@ -212,6 +215,8 @@ func (recv LogLevel) String() string {
212215
}
213216
}
214217

218+
// LogField represents a structured log field with a name and value.
219+
// It is used to provide structured logging information.
215220
type LogField struct {
216221
Name string
217222
Value LogFieldValue
@@ -277,7 +282,9 @@ type LogFieldValue struct {
277282
any interface{}
278283
}
279284

280-
// LogFieldValueType is the type of a LogFieldValue.
285+
// LogFieldValueType represents the type of a LogFieldValue.
286+
// It is used to determine how to interpret the value stored in LogFieldValue.
287+
// Available types: LogFieldTypeAny, LogFieldTypeBool, LogFieldTypeInt64, LogFieldTypeString.
281288
type LogFieldValueType int
282289

283290
// It's important that LogFieldTypeAny is 0 so that a zero Value represents nil.

marshal.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
)
4848

4949
var (
50+
// Deprecated: Never used or returned by the driver.
5051
ErrorUDTUnavailable = errors.New("UDT are not available on protocols less than 3, please update config")
5152
)
5253

@@ -1807,6 +1808,8 @@ func (t listSetCQLType) TypeInfoFromString(proto int, name string) (TypeInfo, er
18071808
}, nil
18081809
}
18091810

1811+
// CollectionType represents type information for Cassandra collection types (list, set, map).
1812+
// It provides marshaling and unmarshaling for collection types.
18101813
type CollectionType struct {
18111814
typ Type
18121815
Key TypeInfo // only used for TypeMap
@@ -2483,7 +2486,8 @@ func (t tupleCQLType) TypeInfoFromString(proto int, name string) (TypeInfo, erro
24832486
}, nil
24842487
}
24852488

2486-
// TODO: move to types.go
2489+
// TupleTypeInfo represents type information for Cassandra tuple types.
2490+
// It contains information about the element types in the tuple.
24872491
type TupleTypeInfo struct {
24882492
Elems []TypeInfo
24892493
}
@@ -2823,11 +2827,15 @@ func (u udtCQLType) TypeInfoFromString(proto int, name string) (TypeInfo, error)
28232827
return ti, nil
28242828
}
28252829

2830+
// UDTField represents a field in a User Defined Type.
2831+
// It contains the field name and its type information.
28262832
type UDTField struct {
28272833
Name string
28282834
Type TypeInfo
28292835
}
28302836

2837+
// UDTTypeInfo represents type information for Cassandra User Defined Types (UDT).
2838+
// It contains the keyspace, type name, and field definitions.
28312839
type UDTTypeInfo struct {
28322840
Keyspace string
28332841
Name string
@@ -3043,6 +3051,7 @@ func (udt UDTTypeInfo) Unmarshal(data []byte, value interface{}) error {
30433051
return nil
30443052
}
30453053

3054+
// MarshalError represents an error that occurred during marshaling.
30463055
type MarshalError string
30473056

30483057
func (m MarshalError) Error() string {
@@ -3053,6 +3062,7 @@ func marshalErrorf(format string, args ...interface{}) MarshalError {
30533062
return MarshalError(fmt.Sprintf(format, args...))
30543063
}
30553064

3065+
// UnmarshalError represents an error that occurred during unmarshaling.
30563066
type UnmarshalError string
30573067

30583068
func (m UnmarshalError) Error() string {

metadata.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,46 @@ type MaterializedViewMetadata struct {
135135
baseTableName string
136136
}
137137

138+
// UserTypeMetadata represents metadata information about a Cassandra User Defined Type (UDT).
139+
// This Go struct holds descriptive information about a UDT that exists in the Cassandra schema,
140+
// including the type name, keyspace, field names, and field types. It is not the UDT itself,
141+
// but rather a representation of the UDT's schema structure for use within the gocql driver.
142+
//
143+
// A Cassandra User Defined Type is a custom data type that allows you to group related fields
144+
// together. This metadata struct provides the necessary information to marshal and unmarshal
145+
// values to and from the corresponding UDT in Cassandra.
146+
//
147+
// For type information used in marshaling/unmarshaling operations, see UDTTypeInfo.
148+
// Actual UDT values are typically represented as map[string]interface{}, Go structs with
149+
// cql tags, or types implementing UDTMarshaler/UDTUnmarshaler interfaces.
138150
type UserTypeMetadata struct {
139-
Keyspace string
140-
Name string
141-
FieldNames []string
142-
FieldTypes []TypeInfo
151+
Keyspace string // The keyspace where the UDT is defined
152+
Name string // The name of the User Defined Type
153+
FieldNames []string // Ordered list of field names in the UDT
154+
FieldTypes []TypeInfo // Corresponding type information for each field
143155
}
144156

145-
// the ordering of the column with regard to its comparator
157+
// ColumnOrder represents the ordering of a column with regard to its comparator.
158+
// It indicates whether the column is sorted in ascending or descending order.
159+
// Available values: ASC, DESC.
146160
type ColumnOrder bool
147161

148162
const (
149163
ASC ColumnOrder = false
150164
DESC ColumnOrder = true
151165
)
152166

167+
// ColumnIndexMetadata represents metadata for a column index in Cassandra.
168+
// It contains the index name, type, and configuration options.
153169
type ColumnIndexMetadata struct {
154170
Name string
155171
Type string
156172
Options map[string]interface{}
157173
}
158174

175+
// ColumnKind represents the kind of column in a Cassandra table.
176+
// It indicates whether the column is part of the partition key, clustering key, or a regular column.
177+
// Available values: ColumnUnkownKind, ColumnPartitionKey, ColumnClusteringKey, ColumnRegular, ColumnCompact, ColumnStatic.
159178
type ColumnKind int
160179

161180
const (

policies.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ type RetryableQuery interface {
122122
Context() context.Context
123123
}
124124

125+
// RetryType represents the type of retry that should be performed by the retry policy.
126+
// Available types: Retry, RetryNextHost, Ignore, Rethrow.
125127
type RetryType uint16
126128

127129
const (
@@ -265,13 +267,18 @@ func (e *ExponentialBackoffRetryPolicy) napTime(attempts int) time.Duration {
265267
return getExponentialTime(e.Min, e.Max, attempts)
266268
}
267269

270+
// HostStateNotifier is an interface for notifying about host state changes.
271+
// It allows host selection policies to be informed when hosts are added, removed,
272+
// or change their availability status.
268273
type HostStateNotifier interface {
269274
AddHost(host *HostInfo)
270275
RemoveHost(host *HostInfo)
271276
HostUp(host *HostInfo)
272277
HostDown(host *HostInfo)
273278
}
274279

280+
// KeyspaceUpdateEvent represents a keyspace change event.
281+
// It contains information about which keyspace changed and what type of change occurred.
275282
type KeyspaceUpdateEvent struct {
276283
Keyspace string
277284
Change string
@@ -947,16 +954,22 @@ func (e *ExponentialReconnectionPolicy) GetMaxRetries() int {
947954
return e.MaxRetries
948955
}
949956

957+
// SpeculativeExecutionPolicy defines the interface for speculative execution policies.
958+
// These policies determine when and how many speculative queries to execute.
950959
type SpeculativeExecutionPolicy interface {
951960
Attempts() int
952961
Delay() time.Duration
953962
}
954963

964+
// NonSpeculativeExecution is a policy that disables speculative execution.
965+
// It implements SpeculativeExecutionPolicy with zero attempts.
955966
type NonSpeculativeExecution struct{}
956967

957968
func (sp NonSpeculativeExecution) Attempts() int { return 0 } // No additional attempts
958969
func (sp NonSpeculativeExecution) Delay() time.Duration { return 1 } // The delay. Must be positive to be used in a ticker.
959970

971+
// SimpleSpeculativeExecution is a policy that enables speculative execution
972+
// with a fixed number of attempts and delay.
960973
type SimpleSpeculativeExecution struct {
961974
NumAttempts int
962975
TimeoutDelay time.Duration

0 commit comments

Comments
 (0)