diff --git a/field.go b/field.go index 996d07341..fd9918838 100644 --- a/field.go +++ b/field.go @@ -131,11 +131,7 @@ func OptFieldTypeInt(min, max int64) FieldOption { } } -func OptFieldTypeTime(timeQuantum TimeQuantum) FieldOption { - return OptFieldTypeTimeOptions(timeQuantum, false) -} - -func OptFieldTypeTimeOptions(timeQuantum TimeQuantum, noStandardView bool) FieldOption { +func OptFieldTypeTime(timeQuantum TimeQuantum, opt ...bool) FieldOption { return func(fo *FieldOptions) error { if fo.Type != "" { return errors.Errorf("field type is already set to: %s", fo.Type) @@ -145,7 +141,7 @@ func OptFieldTypeTimeOptions(timeQuantum TimeQuantum, noStandardView bool) Field } fo.Type = FieldTypeTime fo.TimeQuantum = timeQuantum - fo.NoStandardView = noStandardView + fo.NoStandardView = len(opt) >= 1 && opt[0] return nil } } diff --git a/http/handler.go b/http/handler.go index 3655ed50e..4e9618a7e 100644 --- a/http/handler.go +++ b/http/handler.go @@ -704,7 +704,7 @@ func (h *Handler) handlePostField(w http.ResponseWriter, r *http.Request) { case pilosa.FieldTypeInt: fos = append(fos, pilosa.OptFieldTypeInt(*req.Options.Min, *req.Options.Max)) case pilosa.FieldTypeTime: - fos = append(fos, pilosa.OptFieldTypeTimeOptions(*req.Options.TimeQuantum, req.Options.NoStandardView)) + fos = append(fos, pilosa.OptFieldTypeTime(*req.Options.TimeQuantum, req.Options.NoStandardView)) case pilosa.FieldTypeMutex: fos = append(fos, pilosa.OptFieldTypeMutex(*req.Options.CacheType, *req.Options.CacheSize)) case pilosa.FieldTypeBool: diff --git a/index_test.go b/index_test.go index 13a2b739b..21f9a91d9 100644 --- a/index_test.go +++ b/index_test.go @@ -77,7 +77,7 @@ func TestIndex_CreateField(t *testing.T) { defer index.Close() // Create field with explicit quantum with no standard view - f, err := index.CreateField("f", pilosa.OptFieldTypeTimeOptions(pilosa.TimeQuantum("YMDH"), true)) + f, err := index.CreateField("f", pilosa.OptFieldTypeTime(pilosa.TimeQuantum("YMDH"), true)) if err != nil { t.Fatal(err) } else if q := f.TimeQuantum(); q != pilosa.TimeQuantum("YMDH") { diff --git a/server/server_test.go b/server/server_test.go index 66e8d011d..3aa11b8a2 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -634,7 +634,7 @@ func TestMain_ImportTimestampNoStandardView(t *testing.T) { } // Create field. - if _, err := m.API.CreateField(context.Background(), indexName, fieldName, pilosa.OptFieldTypeTimeOptions(pilosa.TimeQuantum("YMD"), true)); err != nil { + if _, err := m.API.CreateField(context.Background(), indexName, fieldName, pilosa.OptFieldTypeTime(pilosa.TimeQuantum("YMD"), true)); err != nil { t.Fatal(err) }