diff --git a/api.go b/api.go index f0e2dbfb0..f9efbdb00 100644 --- a/api.go +++ b/api.go @@ -244,7 +244,7 @@ func (api *API) CreateField(ctx context.Context, indexName string, fieldName str } // Apply functional option. - fo := FieldOptions{} + fo := fieldOptions{} err := opts(&fo) if err != nil { return nil, errors.Wrap(err, "applying option") diff --git a/field.go b/field.go index 2b78176e1..f2cb711c2 100644 --- a/field.go +++ b/field.go @@ -68,25 +68,25 @@ type Field struct { Stats StatsClient // Field options. - options FieldOptions + options fieldOptions bsiGroups []*bsiGroup Logger Logger } -// FieldOption is a functional option type for pilosa.FieldOptions. -type FieldOption func(fo *FieldOptions) error +// FieldOption is a functional option type for pilosa.fieldOptions. +type FieldOption func(fo *fieldOptions) error func OptFieldKeys() FieldOption { - return func(fo *FieldOptions) error { + return func(fo *fieldOptions) error { fo.Keys = true return nil } } func OptFieldTypeDefault() FieldOption { - return func(fo *FieldOptions) error { + return func(fo *fieldOptions) error { if fo.Type != "" { return errors.Errorf("field type is already set to: %s", fo.Type) } @@ -98,7 +98,7 @@ func OptFieldTypeDefault() FieldOption { } func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption { - return func(fo *FieldOptions) error { + return func(fo *fieldOptions) error { if fo.Type != "" { return errors.Errorf("field type is already set to: %s", fo.Type) } @@ -110,7 +110,7 @@ func OptFieldTypeSet(cacheType string, cacheSize uint32) FieldOption { } func OptFieldTypeInt(min, max int64) FieldOption { - return func(fo *FieldOptions) error { + return func(fo *fieldOptions) error { if fo.Type != "" { return errors.Errorf("field type is already set to: %s", fo.Type) } @@ -125,7 +125,7 @@ func OptFieldTypeInt(min, max int64) FieldOption { } func OptFieldTypeTime(timeQuantum TimeQuantum) FieldOption { - return func(fo *FieldOptions) error { + return func(fo *fieldOptions) error { if fo.Type != "" { return errors.Errorf("field type is already set to: %s", fo.Type) } @@ -146,7 +146,7 @@ func NewField(path, index, name string, opts FieldOption) (*Field, error) { } // Apply functional option. - fo := FieldOptions{} + fo := fieldOptions{} err = opts(&fo) if err != nil { return nil, errors.Wrap(err, "applying option") @@ -240,7 +240,7 @@ func (f *Field) CacheSize() uint32 { } // Options returns all options for this field. -func (f *Field) Options() FieldOptions { +func (f *Field) Options() fieldOptions { f.mu.RLock() defer f.mu.RUnlock() return f.options @@ -358,7 +358,7 @@ func (f *Field) saveMeta() error { } // applyOptions configures the field based on opt. -func (f *Field) applyOptions(opt FieldOptions) error { +func (f *Field) applyOptions(opt fieldOptions) error { switch opt.Type { case FieldTypeSet, "": f.options.Type = FieldTypeSet @@ -1102,7 +1102,7 @@ func (f *Field) ImportValue(columnIDs []uint64, values []int64) error { func (f *Field) MarshalJSON() ([]byte, error) { thing := struct { Name string - Options FieldOptions + Options fieldOptions Views []*viewInfo }{ Name: f.Name(), @@ -1142,7 +1142,7 @@ func (p fieldSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } // FieldInfo represents schema information for a field. type FieldInfo struct { Name string `json:"name"` - Options FieldOptions `json:"options"` + Options fieldOptions `json:"options"` Views []*viewInfo `json:"views,omitempty"` } @@ -1152,8 +1152,8 @@ func (p fieldInfoSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p fieldInfoSlice) Len() int { return len(p) } func (p fieldInfoSlice) Less(i, j int) bool { return p[i].Name < p[j].Name } -// FieldOptions represents options to set when initializing a field. -type FieldOptions struct { +// fieldOptions represents options to set when initializing a field. +type fieldOptions struct { Type string `json:"type,omitempty"` CacheType string `json:"cacheType,omitempty"` CacheSize uint32 `json:"cacheSize,omitempty"` @@ -1163,11 +1163,11 @@ type FieldOptions struct { Keys bool `json:"keys,omitempty"` } -// applyDefaultOptions returns a new FieldOptions object +// applyDefaultOptions returns a new fieldOptions object // with default values if o does not contain a valid type. -func applyDefaultOptions(o FieldOptions) FieldOptions { +func applyDefaultOptions(o fieldOptions) fieldOptions { if o.Type == "" { - return FieldOptions{ + return fieldOptions{ Type: DefaultFieldType, CacheType: DefaultCacheType, CacheSize: DefaultCacheSize, @@ -1177,11 +1177,11 @@ func applyDefaultOptions(o FieldOptions) FieldOptions { } // Encode converts o into its internal representation. -func (o *FieldOptions) Encode() *internal.FieldOptions { +func (o *fieldOptions) Encode() *internal.FieldOptions { return encodeFieldOptions(o) } -func encodeFieldOptions(o *FieldOptions) *internal.FieldOptions { +func encodeFieldOptions(o *fieldOptions) *internal.FieldOptions { if o == nil { return nil } @@ -1196,11 +1196,11 @@ func encodeFieldOptions(o *FieldOptions) *internal.FieldOptions { } } -func decodeFieldOptions(options *internal.FieldOptions) *FieldOptions { +func decodeFieldOptions(options *internal.FieldOptions) *fieldOptions { if options == nil { return nil } - return &FieldOptions{ + return &fieldOptions{ Type: options.Type, CacheType: options.CacheType, CacheSize: options.CacheSize, @@ -1211,7 +1211,7 @@ func decodeFieldOptions(options *internal.FieldOptions) *FieldOptions { } } -func (o *FieldOptions) MarshalJSON() ([]byte, error) { +func (o *fieldOptions) MarshalJSON() ([]byte, error) { switch o.Type { case FieldTypeSet: return json.Marshal(struct { diff --git a/http/handler.go b/http/handler.go index 9195f05e9..1089c5329 100644 --- a/http/handler.go +++ b/http/handler.go @@ -671,7 +671,7 @@ type postFieldRequest struct { Options fieldOptions `json:"options"` } -// fieldOptions tracks pilosa.FieldOptions. It is made up of pointers to values, +// fieldOptions tracks pilosa.fieldOptions. It is made up of pointers to values, // and used for input validation. type fieldOptions struct { Type string `json:"type,omitempty"` diff --git a/index.go b/index.go index 882bc75d3..bf0e55290 100644 --- a/index.go +++ b/index.go @@ -297,7 +297,7 @@ func (i *Index) CreateField(name string, opts ...FieldOption) (*Field, error) { } // Apply functional options. - fo := FieldOptions{} + fo := fieldOptions{} for _, opt := range opts { err := opt(&fo) if err != nil { @@ -319,7 +319,7 @@ func (i *Index) CreateFieldIfNotExists(name string, opts FieldOption) (*Field, e } // Apply functional option. - fo := FieldOptions{} + fo := fieldOptions{} err := opts(&fo) if err != nil { return nil, errors.Wrap(err, "applying option") @@ -328,7 +328,7 @@ func (i *Index) CreateFieldIfNotExists(name string, opts FieldOption) (*Field, e return i.createField(name, fo) } -func (i *Index) createFieldIfNotExists(name string, opt FieldOptions) (*Field, error) { +func (i *Index) createFieldIfNotExists(name string, opt fieldOptions) (*Field, error) { i.mu.Lock() defer i.mu.Unlock() @@ -340,7 +340,7 @@ func (i *Index) createFieldIfNotExists(name string, opt FieldOptions) (*Field, e return i.createField(name, opt) } -func (i *Index) createField(name string, opt FieldOptions) (*Field, error) { +func (i *Index) createField(name string, opt fieldOptions) (*Field, error) { if name == "" { return nil, errors.New("field name required") } else if opt.CacheType != "" && !isValidCacheType(opt.CacheType) { @@ -376,7 +376,7 @@ func (i *Index) createField(name string, opt FieldOptions) (*Field, error) { } func (i *Index) newField(path, name string) (*Field, error) { - f, err := NewField(path, i.name, name, OptFieldTypeDefault()) // TODO: NewField should be un-exported along with FieldOptions + f, err := NewField(path, i.name, name, OptFieldTypeDefault()) if err != nil { return nil, err }