Skip to content

Commit 0640a54

Browse files
authored
godoc: Change const groups so enum values are grouped with type (#1109)
* godoc: Change const groups so enum values are grouped with type Use the `const Name Type = expression` syntax for all typed enum constants. This causes the godoc tool to group the consts with the type definition, which makes it easier to find in the package API documentation. The godoc tool does not group consts if the type comes from the right hand side, as `const Name = Type(expression)`. This is the syntax the kafka package uses. This means most enum const values are not easily found. For example, type OffsetSpec does not show the defined constant values: https://pkg.go.dev/github.com/confluentinc/confluent-kafka-go/[email protected]/kafka#OffsetSpec Instead, the constants are in the package Constants section at the top: https://pkg.go.dev/github.com/confluentinc/confluent-kafka-go/[email protected]/kafka#pkg-constants The ErrorCode type uses the correct syntax: https://pkg.go.dev/github.com/confluentinc/confluent-kafka-go/[email protected]/kafka#ErrorCode This is much easier to understand. This change removes a redundant type from the generated ErrorCode syntax since it is unneeded. This makes the syntax consistent with the other const groups. For more details, see Go's documentation about const grouping: https://tip.golang.org/doc/comment#const * missed ConsumerGroupStates found via code review * Missing type from LatestOffsetSpec
1 parent af4a5f8 commit 0640a54

File tree

5 files changed

+216
-216
lines changed

5 files changed

+216
-216
lines changed

kafka/adminapi.go

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,17 @@ type ConsumerGroupState int
211211

212212
const (
213213
// ConsumerGroupStateUnknown - Unknown ConsumerGroupState
214-
ConsumerGroupStateUnknown = ConsumerGroupState(C.RD_KAFKA_CONSUMER_GROUP_STATE_UNKNOWN)
214+
ConsumerGroupStateUnknown ConsumerGroupState = C.RD_KAFKA_CONSUMER_GROUP_STATE_UNKNOWN
215215
// ConsumerGroupStatePreparingRebalance - preparing rebalance
216-
ConsumerGroupStatePreparingRebalance = ConsumerGroupState(C.RD_KAFKA_CONSUMER_GROUP_STATE_PREPARING_REBALANCE)
216+
ConsumerGroupStatePreparingRebalance ConsumerGroupState = C.RD_KAFKA_CONSUMER_GROUP_STATE_PREPARING_REBALANCE
217217
// ConsumerGroupStateCompletingRebalance - completing rebalance
218-
ConsumerGroupStateCompletingRebalance = ConsumerGroupState(C.RD_KAFKA_CONSUMER_GROUP_STATE_COMPLETING_REBALANCE)
218+
ConsumerGroupStateCompletingRebalance ConsumerGroupState = C.RD_KAFKA_CONSUMER_GROUP_STATE_COMPLETING_REBALANCE
219219
// ConsumerGroupStateStable - stable
220-
ConsumerGroupStateStable = ConsumerGroupState(C.RD_KAFKA_CONSUMER_GROUP_STATE_STABLE)
220+
ConsumerGroupStateStable ConsumerGroupState = C.RD_KAFKA_CONSUMER_GROUP_STATE_STABLE
221221
// ConsumerGroupStateDead - dead group
222-
ConsumerGroupStateDead = ConsumerGroupState(C.RD_KAFKA_CONSUMER_GROUP_STATE_DEAD)
222+
ConsumerGroupStateDead ConsumerGroupState = C.RD_KAFKA_CONSUMER_GROUP_STATE_DEAD
223223
// ConsumerGroupStateEmpty - empty group
224-
ConsumerGroupStateEmpty = ConsumerGroupState(C.RD_KAFKA_CONSUMER_GROUP_STATE_EMPTY)
224+
ConsumerGroupStateEmpty ConsumerGroupState = C.RD_KAFKA_CONSUMER_GROUP_STATE_EMPTY
225225
)
226226

227227
// String returns the human-readable representation of a consumer_group_state
@@ -431,15 +431,15 @@ type ResourceType int
431431

432432
const (
433433
// ResourceUnknown - Unknown
434-
ResourceUnknown = ResourceType(C.RD_KAFKA_RESOURCE_UNKNOWN)
434+
ResourceUnknown ResourceType = C.RD_KAFKA_RESOURCE_UNKNOWN
435435
// ResourceAny - match any resource type (DescribeConfigs)
436-
ResourceAny = ResourceType(C.RD_KAFKA_RESOURCE_ANY)
436+
ResourceAny ResourceType = C.RD_KAFKA_RESOURCE_ANY
437437
// ResourceTopic - Topic
438-
ResourceTopic = ResourceType(C.RD_KAFKA_RESOURCE_TOPIC)
438+
ResourceTopic ResourceType = C.RD_KAFKA_RESOURCE_TOPIC
439439
// ResourceGroup - Group
440-
ResourceGroup = ResourceType(C.RD_KAFKA_RESOURCE_GROUP)
440+
ResourceGroup ResourceType = C.RD_KAFKA_RESOURCE_GROUP
441441
// ResourceBroker - Broker
442-
ResourceBroker = ResourceType(C.RD_KAFKA_RESOURCE_BROKER)
442+
ResourceBroker ResourceType = C.RD_KAFKA_RESOURCE_BROKER
443443
)
444444

445445
// String returns the human-readable representation of a ResourceType
@@ -469,17 +469,17 @@ type ConfigSource int
469469

470470
const (
471471
// ConfigSourceUnknown is the default value
472-
ConfigSourceUnknown = ConfigSource(C.RD_KAFKA_CONFIG_SOURCE_UNKNOWN_CONFIG)
472+
ConfigSourceUnknown ConfigSource = C.RD_KAFKA_CONFIG_SOURCE_UNKNOWN_CONFIG
473473
// ConfigSourceDynamicTopic is dynamic topic config that is configured for a specific topic
474-
ConfigSourceDynamicTopic = ConfigSource(C.RD_KAFKA_CONFIG_SOURCE_DYNAMIC_TOPIC_CONFIG)
474+
ConfigSourceDynamicTopic ConfigSource = C.RD_KAFKA_CONFIG_SOURCE_DYNAMIC_TOPIC_CONFIG
475475
// ConfigSourceDynamicBroker is dynamic broker config that is configured for a specific broker
476-
ConfigSourceDynamicBroker = ConfigSource(C.RD_KAFKA_CONFIG_SOURCE_DYNAMIC_BROKER_CONFIG)
476+
ConfigSourceDynamicBroker ConfigSource = C.RD_KAFKA_CONFIG_SOURCE_DYNAMIC_BROKER_CONFIG
477477
// ConfigSourceDynamicDefaultBroker is dynamic broker config that is configured as default for all brokers in the cluster
478-
ConfigSourceDynamicDefaultBroker = ConfigSource(C.RD_KAFKA_CONFIG_SOURCE_DYNAMIC_DEFAULT_BROKER_CONFIG)
478+
ConfigSourceDynamicDefaultBroker ConfigSource = C.RD_KAFKA_CONFIG_SOURCE_DYNAMIC_DEFAULT_BROKER_CONFIG
479479
// ConfigSourceStaticBroker is static broker config provided as broker properties at startup (e.g. from server.properties file)
480-
ConfigSourceStaticBroker = ConfigSource(C.RD_KAFKA_CONFIG_SOURCE_STATIC_BROKER_CONFIG)
480+
ConfigSourceStaticBroker ConfigSource = C.RD_KAFKA_CONFIG_SOURCE_STATIC_BROKER_CONFIG
481481
// ConfigSourceDefault is built-in default configuration for configs that have a default value
482-
ConfigSourceDefault = ConfigSource(C.RD_KAFKA_CONFIG_SOURCE_DEFAULT_CONFIG)
482+
ConfigSourceDefault ConfigSource = C.RD_KAFKA_CONFIG_SOURCE_DEFAULT_CONFIG
483483
)
484484

485485
// String returns the human-readable representation of a ConfigSource type
@@ -531,16 +531,16 @@ type AlterConfigOpType int
531531
const (
532532
// AlterConfigOpTypeSet sets/overwrites the configuration
533533
// setting.
534-
AlterConfigOpTypeSet = AlterConfigOpType(C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_SET)
534+
AlterConfigOpTypeSet AlterConfigOpType = C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_SET
535535
// AlterConfigOpTypeDelete sets the configuration setting
536536
// to default or NULL.
537-
AlterConfigOpTypeDelete = AlterConfigOpType(C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_DELETE)
537+
AlterConfigOpTypeDelete AlterConfigOpType = C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_DELETE
538538
// AlterConfigOpTypeAppend appends the value to existing
539539
// configuration settings.
540-
AlterConfigOpTypeAppend = AlterConfigOpType(C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_APPEND)
540+
AlterConfigOpTypeAppend AlterConfigOpType = C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_APPEND
541541
// AlterConfigOpTypeSubtract subtracts the value from
542542
// existing configuration settings.
543-
AlterConfigOpTypeSubtract = AlterConfigOpType(C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_SUBTRACT)
543+
AlterConfigOpTypeSubtract AlterConfigOpType = C.RD_KAFKA_ALTER_CONFIG_OP_TYPE_SUBTRACT
544544
)
545545

546546
// String returns the human-readable representation of an AlterOperation
@@ -682,15 +682,15 @@ type ResourcePatternType int
682682

683683
const (
684684
// ResourcePatternTypeUnknown is a resource pattern type not known or not set.
685-
ResourcePatternTypeUnknown = ResourcePatternType(C.RD_KAFKA_RESOURCE_PATTERN_UNKNOWN)
685+
ResourcePatternTypeUnknown ResourcePatternType = C.RD_KAFKA_RESOURCE_PATTERN_UNKNOWN
686686
// ResourcePatternTypeAny matches any resource, used for lookups.
687-
ResourcePatternTypeAny = ResourcePatternType(C.RD_KAFKA_RESOURCE_PATTERN_ANY)
687+
ResourcePatternTypeAny ResourcePatternType = C.RD_KAFKA_RESOURCE_PATTERN_ANY
688688
// ResourcePatternTypeMatch will perform pattern matching
689-
ResourcePatternTypeMatch = ResourcePatternType(C.RD_KAFKA_RESOURCE_PATTERN_MATCH)
689+
ResourcePatternTypeMatch ResourcePatternType = C.RD_KAFKA_RESOURCE_PATTERN_MATCH
690690
// ResourcePatternTypeLiteral matches a literal resource name
691-
ResourcePatternTypeLiteral = ResourcePatternType(C.RD_KAFKA_RESOURCE_PATTERN_LITERAL)
691+
ResourcePatternTypeLiteral ResourcePatternType = C.RD_KAFKA_RESOURCE_PATTERN_LITERAL
692692
// ResourcePatternTypePrefixed matches a prefixed resource name
693-
ResourcePatternTypePrefixed = ResourcePatternType(C.RD_KAFKA_RESOURCE_PATTERN_PREFIXED)
693+
ResourcePatternTypePrefixed ResourcePatternType = C.RD_KAFKA_RESOURCE_PATTERN_PREFIXED
694694
)
695695

696696
// String returns the human-readable representation of a ResourcePatternType
@@ -720,31 +720,31 @@ type ACLOperation int
720720

721721
const (
722722
// ACLOperationUnknown represents an unknown or unset operation
723-
ACLOperationUnknown = ACLOperation(C.RD_KAFKA_ACL_OPERATION_UNKNOWN)
723+
ACLOperationUnknown ACLOperation = C.RD_KAFKA_ACL_OPERATION_UNKNOWN
724724
// ACLOperationAny in a filter, matches any ACLOperation
725-
ACLOperationAny = ACLOperation(C.RD_KAFKA_ACL_OPERATION_ANY)
725+
ACLOperationAny ACLOperation = C.RD_KAFKA_ACL_OPERATION_ANY
726726
// ACLOperationAll represents all the operations
727-
ACLOperationAll = ACLOperation(C.RD_KAFKA_ACL_OPERATION_ALL)
727+
ACLOperationAll ACLOperation = C.RD_KAFKA_ACL_OPERATION_ALL
728728
// ACLOperationRead a read operation
729-
ACLOperationRead = ACLOperation(C.RD_KAFKA_ACL_OPERATION_READ)
729+
ACLOperationRead ACLOperation = C.RD_KAFKA_ACL_OPERATION_READ
730730
// ACLOperationWrite represents a write operation
731-
ACLOperationWrite = ACLOperation(C.RD_KAFKA_ACL_OPERATION_WRITE)
731+
ACLOperationWrite ACLOperation = C.RD_KAFKA_ACL_OPERATION_WRITE
732732
// ACLOperationCreate represents a create operation
733-
ACLOperationCreate = ACLOperation(C.RD_KAFKA_ACL_OPERATION_CREATE)
733+
ACLOperationCreate ACLOperation = C.RD_KAFKA_ACL_OPERATION_CREATE
734734
// ACLOperationDelete represents a delete operation
735-
ACLOperationDelete = ACLOperation(C.RD_KAFKA_ACL_OPERATION_DELETE)
735+
ACLOperationDelete ACLOperation = C.RD_KAFKA_ACL_OPERATION_DELETE
736736
// ACLOperationAlter represents an alter operation
737-
ACLOperationAlter = ACLOperation(C.RD_KAFKA_ACL_OPERATION_ALTER)
737+
ACLOperationAlter ACLOperation = C.RD_KAFKA_ACL_OPERATION_ALTER
738738
// ACLOperationDescribe represents a describe operation
739-
ACLOperationDescribe = ACLOperation(C.RD_KAFKA_ACL_OPERATION_DESCRIBE)
739+
ACLOperationDescribe ACLOperation = C.RD_KAFKA_ACL_OPERATION_DESCRIBE
740740
// ACLOperationClusterAction represents a cluster action operation
741-
ACLOperationClusterAction = ACLOperation(C.RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION)
741+
ACLOperationClusterAction ACLOperation = C.RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION
742742
// ACLOperationDescribeConfigs represents a describe configs operation
743-
ACLOperationDescribeConfigs = ACLOperation(C.RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS)
743+
ACLOperationDescribeConfigs ACLOperation = C.RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS
744744
// ACLOperationAlterConfigs represents an alter configs operation
745-
ACLOperationAlterConfigs = ACLOperation(C.RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS)
745+
ACLOperationAlterConfigs ACLOperation = C.RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS
746746
// ACLOperationIdempotentWrite represents an idempotent write operation
747-
ACLOperationIdempotentWrite = ACLOperation(C.RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE)
747+
ACLOperationIdempotentWrite ACLOperation = C.RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE
748748
)
749749

750750
// String returns the human-readable representation of an ACLOperation
@@ -790,13 +790,13 @@ type ACLPermissionType int
790790

791791
const (
792792
// ACLPermissionTypeUnknown represents an unknown ACLPermissionType
793-
ACLPermissionTypeUnknown = ACLPermissionType(C.RD_KAFKA_ACL_PERMISSION_TYPE_UNKNOWN)
793+
ACLPermissionTypeUnknown ACLPermissionType = C.RD_KAFKA_ACL_PERMISSION_TYPE_UNKNOWN
794794
// ACLPermissionTypeAny in a filter, matches any ACLPermissionType
795-
ACLPermissionTypeAny = ACLPermissionType(C.RD_KAFKA_ACL_PERMISSION_TYPE_ANY)
795+
ACLPermissionTypeAny ACLPermissionType = C.RD_KAFKA_ACL_PERMISSION_TYPE_ANY
796796
// ACLPermissionTypeDeny disallows access
797-
ACLPermissionTypeDeny = ACLPermissionType(C.RD_KAFKA_ACL_PERMISSION_TYPE_DENY)
797+
ACLPermissionTypeDeny ACLPermissionType = C.RD_KAFKA_ACL_PERMISSION_TYPE_DENY
798798
// ACLPermissionTypeAllow grants access
799-
ACLPermissionTypeAllow = ACLPermissionType(C.RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW)
799+
ACLPermissionTypeAllow ACLPermissionType = C.RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW
800800
)
801801

802802
// String returns the human-readable representation of an ACLPermissionType
@@ -903,11 +903,11 @@ type ScramMechanism int
903903

904904
const (
905905
// ScramMechanismUnknown - Unknown SASL/SCRAM mechanism
906-
ScramMechanismUnknown = ScramMechanism(C.RD_KAFKA_SCRAM_MECHANISM_UNKNOWN)
906+
ScramMechanismUnknown ScramMechanism = C.RD_KAFKA_SCRAM_MECHANISM_UNKNOWN
907907
// ScramMechanismSHA256 - SCRAM-SHA-256 mechanism
908-
ScramMechanismSHA256 = ScramMechanism(C.RD_KAFKA_SCRAM_MECHANISM_SHA_256)
908+
ScramMechanismSHA256 ScramMechanism = C.RD_KAFKA_SCRAM_MECHANISM_SHA_256
909909
// ScramMechanismSHA512 - SCRAM-SHA-512 mechanism
910-
ScramMechanismSHA512 = ScramMechanism(C.RD_KAFKA_SCRAM_MECHANISM_SHA_512)
910+
ScramMechanismSHA512 ScramMechanism = C.RD_KAFKA_SCRAM_MECHANISM_SHA_512
911911
)
912912

913913
// String returns the human-readable representation of an ScramMechanism
@@ -1000,11 +1000,11 @@ type OffsetSpec int64
10001000

10011001
const (
10021002
// MaxTimestampOffsetSpec is used to describe the offset with the Max Timestamp which may be different then LatestOffsetSpec as Timestamp can be set client side.
1003-
MaxTimestampOffsetSpec = OffsetSpec(C.RD_KAFKA_OFFSET_SPEC_MAX_TIMESTAMP)
1003+
MaxTimestampOffsetSpec OffsetSpec = C.RD_KAFKA_OFFSET_SPEC_MAX_TIMESTAMP
10041004
// EarliestOffsetSpec is used to describe the earliest offset for the TopicPartition.
1005-
EarliestOffsetSpec = OffsetSpec(C.RD_KAFKA_OFFSET_SPEC_EARLIEST)
1005+
EarliestOffsetSpec OffsetSpec = C.RD_KAFKA_OFFSET_SPEC_EARLIEST
10061006
// LatestOffsetSpec is used to describe the latest offset for the TopicPartition.
1007-
LatestOffsetSpec = OffsetSpec(C.RD_KAFKA_OFFSET_SPEC_LATEST)
1007+
LatestOffsetSpec OffsetSpec = C.RD_KAFKA_OFFSET_SPEC_LATEST
10081008
)
10091009

10101010
// NewOffsetSpecForTimestamp creates an OffsetSpec corresponding to the timestamp.

kafka/adminoptions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ type IsolationLevel int
182182

183183
const (
184184
// IsolationLevelReadUncommitted - read uncommitted isolation level
185-
IsolationLevelReadUncommitted = IsolationLevel(C.RD_KAFKA_ISOLATION_LEVEL_READ_UNCOMMITTED)
185+
IsolationLevelReadUncommitted IsolationLevel = C.RD_KAFKA_ISOLATION_LEVEL_READ_UNCOMMITTED
186186
// IsolationLevelReadCommitted - read committed isolation level
187-
IsolationLevelReadCommitted = IsolationLevel(C.RD_KAFKA_ISOLATION_LEVEL_READ_COMMITTED)
187+
IsolationLevelReadCommitted IsolationLevel = C.RD_KAFKA_ISOLATION_LEVEL_READ_COMMITTED
188188
)
189189

190190
// AdminOptionIsolationLevel sets the overall request IsolationLevel.

kafka/error_gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const (
103103
errname = strings.Replace(errname, "Id", "ID", -1)
104104

105105
f.WriteString(fmt.Sprintf("\t// %s %s\n", errname, desc))
106-
f.WriteString(fmt.Sprintf("\t%s ErrorCode = ErrorCode(C.RD_KAFKA_RESP_ERR_%s)\n",
106+
f.WriteString(fmt.Sprintf("\t%s ErrorCode = C.RD_KAFKA_RESP_ERR_%s\n",
107107
errname, orig))
108108
}
109109

0 commit comments

Comments
 (0)