/
field.go
56 lines (46 loc) · 1.07 KB
/
field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package types
import (
"gopkg.in/actgardner/gogen-avro.v5/generator"
)
/*
* The interface implemented by all Avro field types.
*/
type Field struct {
avroName string
avroType AvroType
defValue interface{}
hasDef bool
definition map[string]interface{}
}
func NewField(avroName string, avroType AvroType, defValue interface{}, hasDef bool, definition map[string]interface{}) *Field {
return &Field{
avroName: avroName,
avroType: avroType,
defValue: defValue,
hasDef: hasDef,
definition: definition,
}
}
func (f *Field) Name() string {
return f.avroName
}
func (f *Field) GoName() string {
return generator.ToPublicName(f.avroName)
}
func (f *Field) HasDefault() bool {
return f.defValue == nil
}
func (f *Field) Default() interface{} {
return f.defValue
}
func (f *Field) Type() AvroType {
return f.avroType
}
func (f *Field) Definition(scope map[QualifiedName]interface{}) (map[string]interface{}, error) {
var err error
f.definition["type"], err = f.avroType.Definition(scope)
if err != nil {
return nil, err
}
return f.definition, nil
}