Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
go-version: [ "1.24", "1.25" ]
env:
GOLANGCI_LINT_VERSION: v2.4.0
GOLANGCI_LINT_VERSION: v2.6.2

steps:
- name: Checkout code
Expand Down
4 changes: 2 additions & 2 deletions cmd/avrogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func parseTags(raw string) (map[string]gen.TagStyle, error) {
}

result := map[string]gen.TagStyle{}
for _, tag := range strings.Split(raw, ",") {
for tag := range strings.SplitSeq(raw, ",") {
parts := strings.Split(tag, ":")
switch {
case len(parts) != 2:
Expand Down Expand Up @@ -271,7 +271,7 @@ func parseInitialisms(raw string) ([]string, error) {
}

result := []string{}
for _, initialism := range strings.Split(raw, ",") {
for initialism := range strings.SplitSeq(raw, ",") {
if initialism != strings.ToUpper(initialism) {
return nil, fmt.Errorf("initialism %q must be fully in upper case", initialism)
}
Expand Down
8 changes: 4 additions & 4 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
)

var (
timeType = reflect.TypeOf(time.Time{})
timeDurationType = reflect.TypeOf(time.Duration(0))
ratType = reflect.TypeOf(big.Rat{})
durType = reflect.TypeOf(LogicalDuration{})
timeType = reflect.TypeFor[time.Time]()
timeDurationType = reflect.TypeFor[time.Duration]()
ratType = reflect.TypeFor[big.Rat]()
durType = reflect.TypeFor[LogicalDuration]()
)

type null struct{}
Expand Down
13 changes: 5 additions & 8 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"maps"
"slices"
"strings"
"text/template"
"unicode/utf8"
Expand Down Expand Up @@ -447,19 +448,15 @@ func (g *Generator) newField(name, typ, doc, avroFieldName string, props map[str
}

func (g *Generator) addImport(pkg string) {
for _, p := range g.imports {
if p == pkg {
return
}
if slices.Contains(g.imports, pkg) {
return
}
g.imports = append(g.imports, pkg)
}

func (g *Generator) addThirdPartyImport(pkg string) {
for _, p := range g.thirdPartyImports {
if p == pkg {
return
}
if slices.Contains(g.thirdPartyImports, pkg) {
return
}
g.thirdPartyImports = append(g.thirdPartyImports, pkg)
}
Expand Down
3 changes: 2 additions & 1 deletion protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"slices"

"github.com/go-viper/mapstructure/v2"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -366,7 +367,7 @@ func parseMessage(namespace string, m map[string]any, seen seenCache, cache *Sch
}

oneWay := msg.OneWay
if hasKey(meta.Keys, "one-way") && oneWay && (len(errs.Types()) > 1 || response != nil) {
if slices.Contains(meta.Keys, "one-way") && oneWay && (len(errs.Types()) > 1 || response != nil) {
return nil, errors.New("avro: one-way messages cannot not have a response or errors")
}
if !oneWay && len(errs.Types()) <= 1 && response == nil {
Expand Down
2 changes: 1 addition & 1 deletion reader_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (r *Reader) ReadMapCB(fn func(*Reader, string) bool) {
}
}

var byteType = reflect.TypeOf((*byte)(nil)).Elem()
var byteType = reflect.TypeFor[byte]()

func byteSliceToArray(b []byte, size int) any {
vArr := reflect.New(reflect.ArrayOf(size, byteType)).Elem()
Expand Down
25 changes: 6 additions & 19 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (c *SchemaCache) AddAll(cache *SchemaCache) {
if cache == nil {
return
}
cache.cache.Range(func(key, value interface{}) bool {
cache.cache.Range(func(key, value any) bool {
c.cache.Store(key, value)
return true
})
Expand Down Expand Up @@ -238,7 +239,7 @@ func newName(n, ns string, aliases []string) (name, error) {
full = ns + "." + n
}

for _, part := range strings.Split(full, ".") {
for part := range strings.SplitSeq(full, ".") {
if err := validateName(part); err != nil {
return name{}, fmt.Errorf("avro: invalid name part %q in name %q: %w", full, part, err)
}
Expand All @@ -258,7 +259,7 @@ func newName(n, ns string, aliases []string) (name, error) {
continue
}

for _, part := range strings.Split(alias, ".") {
for part := range strings.SplitSeq(alias, ".") {
if err := validateName(part); err != nil {
return name{}, fmt.Errorf("avro: invalid name part %q in name %q: %w", full, part, err)
}
Expand Down Expand Up @@ -376,23 +377,14 @@ type properties struct {
func newProperties(props map[string]any, res []string) properties {
p := properties{props: map[string]any{}}
for k, v := range props {
if isReserved(res, k) {
if slices.Contains(res, k) {
continue
}
p.props[k] = v
}
return p
}

func isReserved(res []string, k string) bool {
for _, r := range res {
if k == r {
return true
}
}
return false
}

// Prop gets a property from the schema.
func (p properties) Prop(name string) any {
if p.props == nil {
Expand Down Expand Up @@ -973,12 +965,7 @@ func NewEnumSchema(name, namespace string, symbols []string, opts ...SchemaOptio
}

func hasSymbol(symbols []string, sym string) bool {
for _, s := range symbols {
if s == sym {
return true
}
}
return false
return slices.Contains(symbols, sym)
}

// Type returns the type of the schema.
Expand Down
19 changes: 5 additions & 14 deletions schema_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package avro
import (
"errors"
"fmt"
"slices"
"sync"
)

Expand Down Expand Up @@ -180,7 +181,7 @@ func (c *SchemaCompatibility) match(reader, writer Schema) error {

func (c *SchemaCompatibility) checkSchemaName(reader, writer NamedSchema) error {
if reader.Name() != writer.Name() {
if c.contains(reader.Aliases(), writer.FullName()) {
if slices.Contains(reader.Aliases(), writer.FullName()) {
return nil
}
return fmt.Errorf("reader schema %s and writer schema %s names do not match", reader.FullName(), writer.FullName())
Expand All @@ -199,7 +200,7 @@ func (c *SchemaCompatibility) checkFixedSize(reader, writer *FixedSchema) error

func (c *SchemaCompatibility) checkEnumSymbols(reader, writer *EnumSchema) error {
for _, symbol := range writer.Symbols() {
if !c.contains(reader.Symbols(), symbol) {
if !slices.Contains(reader.Symbols(), symbol) {
return fmt.Errorf("reader %s is missing symbol %s", reader.FullName(), symbol)
}
}
Expand Down Expand Up @@ -240,16 +241,6 @@ func (c *SchemaCompatibility) checkRecordFields(reader, writer *RecordSchema) er
return nil
}

func (c *SchemaCompatibility) contains(a []string, s string) bool {
for _, str := range a {
if str == s {
return true
}
}

return false
}

type getFieldOptions struct {
fieldAlias bool
elemAlias bool
Expand All @@ -265,12 +256,12 @@ func (c *SchemaCompatibility) getField(a []*Field, f *Field, optFns ...func(*get
return field, true
}
if opt.fieldAlias {
if c.contains(f.Aliases(), field.Name()) {
if slices.Contains(f.Aliases(), field.Name()) {
return field, true
}
}
if opt.elemAlias {
if c.contains(field.Aliases(), f.Name()) {
if slices.Contains(field.Aliases(), f.Name()) {
return field, true
}
}
Expand Down
22 changes: 7 additions & 15 deletions schema_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math"
"os"
"path/filepath"
"slices"
"strings"

"github.com/go-viper/mapstructure/v2"
Expand Down Expand Up @@ -247,7 +248,7 @@ func parseRecord(typ Type, namespace string, m map[string]any, seen seenCache, c
r.Namespace = namespace
}

if !hasKey(meta.Keys, "fields") {
if !slices.Contains(meta.Keys, "fields") {
return nil, errors.New("avro: record must have an array of fields")
}
fields := make([]*Field, len(r.Fields))
Expand Down Expand Up @@ -321,15 +322,15 @@ func parseField(namespace string, m map[string]any, seen seenCache, cache *Schem
return nil, err
}

if !hasKey(meta.Keys, "type") {
if !slices.Contains(meta.Keys, "type") {
return nil, errors.New("avro: field requires a type")
}
typ, err := parseType(namespace, f.Type, seen, cache)
if err != nil {
return nil, err
}

if !hasKey(meta.Keys, "default") {
if !slices.Contains(meta.Keys, "default") {
f.Default = NoDefault
}

Expand Down Expand Up @@ -405,7 +406,7 @@ func parseArray(namespace string, m map[string]any, seen seenCache, cache *Schem
return nil, fmt.Errorf("avro: error decoding array: %w", err)
}

if !hasKey(meta.Keys, "items") {
if !slices.Contains(meta.Keys, "items") {
return nil, errors.New("avro: array must have an items key")
}
schema, err := parseType(namespace, a.Items, seen, cache)
Expand All @@ -431,7 +432,7 @@ func parseMap(namespace string, m map[string]any, seen seenCache, cache *SchemaC
return nil, fmt.Errorf("avro: error decoding map: %w", err)
}

if !hasKey(meta.Keys, "values") {
if !slices.Contains(meta.Keys, "values") {
return nil, errors.New("avro: map must have an values key")
}
schema, err := parseType(namespace, ms.Values, seen, cache)
Expand Down Expand Up @@ -480,7 +481,7 @@ func parseFixed(namespace string, m map[string]any, seen seenCache, cache *Schem
f.Namespace = namespace
}

if !hasKey(meta.Keys, "size") {
if !slices.Contains(meta.Keys, "size") {
return nil, errors.New("avro: fixed must have a size")
}

Expand Down Expand Up @@ -583,15 +584,6 @@ func checkParsedName(name string) error {
return nil
}

func hasKey(keys []string, k string) bool {
for _, key := range keys {
if key == k {
return true
}
}
return false
}

func decodeMap(in, v any, meta *mapstructure.Metadata) error {
cfg := &mapstructure.DecoderConfig{
ZeroFields: true,
Expand Down