From fb8cc455b6502297e1d3dd66eae72041edc223e6 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 14 May 2018 17:35:24 -0500 Subject: [PATCH 01/15] remove viewSlice (unused) --- view.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/view.go b/view.go index 4f2ae1cd7..a3ce22661 100644 --- a/view.go +++ b/view.go @@ -433,12 +433,6 @@ func IsInverseView(name string) bool { return strings.HasPrefix(name, ViewInverse) } -type viewSlice []*View - -func (p viewSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } -func (p viewSlice) Len() int { return len(p) } -func (p viewSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } - // ViewInfo represents schema information for a view. type ViewInfo struct { Name string `json:"name"` From eb5187bfd08d619ccd62f79f9af5157f1d7829a6 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 14 May 2018 17:35:43 -0500 Subject: [PATCH 02/15] remove encode/decodeURIs --- uri.go | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/uri.go b/uri.go index dfb82baef..7ab606788 100644 --- a/uri.go +++ b/uri.go @@ -234,28 +234,6 @@ func decodeURI(i *internal.URI) URI { } } -func encodeURIs(a []URI) []*internal.URI { - if len(a) == 0 { - return nil - } - other := make([]*internal.URI, len(a)) - for i := range a { - other[i] = encodeURI(a[i]) - } - return other -} - -func decodeURIs(a []*internal.URI) []URI { - if len(a) == 0 { - return nil - } - other := make([]URI, len(a)) - for i := range a { - other[i] = decodeURI(a[i]) - } - return other -} - // MarshalJSON marshals URI into a JSON-encoded byte slice. func (u *URI) MarshalJSON() ([]byte, error) { var output struct { From b280ab2c4763d7efc67ce262d86d0c48ddf9994f Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 14 May 2018 17:35:55 -0500 Subject: [PATCH 03/15] remove MustParseTimePtr --- time_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/time_test.go b/time_test.go index 0602b60de..233a2ae1a 100644 --- a/time_test.go +++ b/time_test.go @@ -160,12 +160,6 @@ func MustParseTime(value string) time.Time { return v } -// MustParseTimePtr parses value using DefaultTimeLayout. Panic on error. -func MustParseTimePtr(value string) *time.Time { - v := MustParseTime(value) - return &v -} - // MustParseTimeQuantum parses v into a time quantum. Panic on error. func MustParseTimeQuantum(v string) pilosa.TimeQuantum { q, err := pilosa.ParseTimeQuantum(v) From a10750009bf8147b1aab58bb9833ca314e593d43 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 14 May 2018 17:36:31 -0500 Subject: [PATCH 04/15] remove decodeColumnAttrSet(s) (unused) --- pilosa.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/pilosa.go b/pilosa.go index 84d7169a7..f29356ef6 100644 --- a/pilosa.go +++ b/pilosa.go @@ -98,15 +98,6 @@ func encodeColumnAttrSets(a []*ColumnAttrSet) []*internal.ColumnAttrSet { return other } -// decodeColumnAttrSets converts a from its internal representation. -func decodeColumnAttrSets(a []*internal.ColumnAttrSet) []*ColumnAttrSet { - other := make([]*ColumnAttrSet, len(a)) - for i := range a { - other[i] = decodeColumnAttrSet(a[i]) - } - return other -} - // encodeColumnAttrSet converts set into its internal representation. func encodeColumnAttrSet(set *ColumnAttrSet) *internal.ColumnAttrSet { return &internal.ColumnAttrSet{ @@ -115,23 +106,6 @@ func encodeColumnAttrSet(set *ColumnAttrSet) *internal.ColumnAttrSet { } } -// decodeColumnAttrSet converts b from its internal representation. -func decodeColumnAttrSet(pb *internal.ColumnAttrSet) *ColumnAttrSet { - set := &ColumnAttrSet{ - ID: pb.ID, - } - - if len(pb.Attrs) > 0 { - set.Attrs = make(map[string]interface{}, len(pb.Attrs)) - for _, attr := range pb.Attrs { - k, v := decodeAttr(attr) - set.Attrs[k] = v - } - } - - return set -} - // TimeFormat is the go-style time format used to parse string dates. const TimeFormat = "2006-01-02T15:04" From 0c06549a5b08190f011f0d41ad930677ad7467a0 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 14 May 2018 17:41:27 -0500 Subject: [PATCH 05/15] remove unnecessary returns in stats_test.go --- stats_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stats_test.go b/stats_test.go index d6c748c5f..0ec6a0a32 100644 --- a/stats_test.go +++ b/stats_test.go @@ -107,7 +107,6 @@ func TestStatsCount_TopN(t *testing.T) { } called = true - return }, } if _, err := e.Execute(context.Background(), "d", test.MustParse(`TopN(frame=f, n=2)`), nil, nil); err != nil { @@ -137,7 +136,6 @@ func TestStatsCount_Bitmap(t *testing.T) { } called = true - return }, } if _, err := e.Execute(context.Background(), "d", test.MustParse(`Bitmap(frame=f, row=0)`), nil, nil); err != nil { @@ -168,7 +166,6 @@ func TestStatsCount_SetBitmapAttrs(t *testing.T) { t.Errorf("Expected SetBitmapAttrs, Results %s", name) } called = true - return }, } if _, err := e.Execute(context.Background(), "d", test.MustParse(`SetRowAttrs(row=10, frame=f, foo="bar")`), nil, nil); err != nil { @@ -200,7 +197,6 @@ func TestStatsCount_SetProfileAttrs(t *testing.T) { } called = true - return }, } if _, err := e.Execute(context.Background(), "d", test.MustParse(`SetColumnAttrs(col=10, frame=f, foo="bar")`), nil, nil); err != nil { @@ -225,7 +221,6 @@ func TestStatsCount_CreateIndex(t *testing.T) { } called = true - return }, } http.DefaultClient.Do(test.MustNewHTTPRequest("POST", s.URL+"/index/i", nil)) @@ -254,7 +249,6 @@ func TestStatsCount_DeleteIndex(t *testing.T) { } called = true - return }, } http.DefaultClient.Do(test.MustNewHTTPRequest("DELETE", s.URL+"/index/i", strings.NewReader(""))) @@ -286,7 +280,6 @@ func TestStatsCount_CreateFrame(t *testing.T) { } called = true - return }, } http.DefaultClient.Do(test.MustNewHTTPRequest("POST", s.URL+"/index/i/frame/f", nil)) @@ -318,7 +311,6 @@ func TestStatsCount_DeleteFrame(t *testing.T) { } called = true - return }, } http.DefaultClient.Do(test.MustNewHTTPRequest("DELETE", s.URL+"/index/i/frame/f", strings.NewReader(""))) @@ -335,17 +327,13 @@ type MockStats struct { func (s *MockStats) Count(name string, value int64, rate float64) { if s.mockCount != nil { s.mockCount(name, value, rate) - return } - return } func (s *MockStats) CountWithCustomTags(name string, value int64, rate float64, tags []string) { if s.mockCountWithTags != nil { s.mockCountWithTags(name, value, rate, tags) - return } - return } func (c *MockStats) Tags() []string { return nil } From 1550279ebc9d688c47250383b2127a288bbc63cb Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 14 May 2018 17:50:15 -0500 Subject: [PATCH 06/15] simplify some error returns removes unnecessary if statements --- cluster.go | 6 ++---- utils_test.go | 6 +----- view_test.go | 5 +---- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/cluster.go b/cluster.go index aa1c26b55..c770eab98 100644 --- a/cluster.go +++ b/cluster.go @@ -1299,10 +1299,8 @@ func (c *Cluster) FollowResizeInstruction(instr *internal.ResizeInstruction) err // Write to local frame and always close reader. if err := func() error { defer rd.Close() - if _, err := frag.ReadFrom(rd); err != nil { - return err - } - return nil + _, err := frag.ReadFrom(rd) + return err }(); err != nil { return errors.Wrap(err, "copying remote slice") } diff --git a/utils_test.go b/utils_test.go index 05afeac19..f4212e0ec 100644 --- a/utils_test.go +++ b/utils_test.go @@ -417,9 +417,5 @@ func (t *ClusterCluster) FollowResizeInstruction(instr *internal.ResizeInstructi } node := DecodeNode(instr.Coordinator) - if err := t.SendTo(node, complete); err != nil { - return err - } - - return nil + return t.SendTo(node, complete) } diff --git a/view_test.go b/view_test.go index 87ed8e628..7c7f53a26 100644 --- a/view_test.go +++ b/view_test.go @@ -69,10 +69,7 @@ func (v *View) Reopen() error { v.View = pilosa.NewView(path, v.Index(), v.Frame(), v.Name(), pilosa.DefaultCacheSize) v.View.RowAttrStore = v.RowAttrStore - if err := v.Open(); err != nil { - return err - } - return nil + return v.Open() } // MustSetBits sets bits on a row. Panic on error. From 2b311d267c913745646fc9954d6641a4560c07a0 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 10:40:32 -0500 Subject: [PATCH 07/15] check some unchecked errors --- client.go | 3 +++ diagnostics.go | 6 ++++++ handler_test.go | 3 +++ index_test.go | 3 +++ 4 files changed, 15 insertions(+) diff --git a/client.go b/client.go index 72225aef2..0575b838b 100644 --- a/client.go +++ b/client.go @@ -1111,6 +1111,9 @@ func (c *InternalHTTPClient) SendMessage(ctx context.Context, uri *URI, pb proto u := uriPathToURL(uri, "/cluster/message") req, err := http.NewRequest("POST", u.String(), bytes.NewReader(msg)) + if err != nil { + return errors.Wrap(err, "making new request") + } req.Header.Set("Content-Type", "application/x-protobuf") req.Header.Set("User-Agent", "pilosa/"+Version) diff --git a/diagnostics.go b/diagnostics.go index 46ffc2110..9219c01ea 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -85,6 +85,9 @@ func (d *DiagnosticsCollector) Flush() error { return errors.Wrap(err, "encoding") } req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf)) + if err != nil { + return errors.Wrap(err, "making new request") + } req.Header.Set("Content-Type", "application/json") resp, err := d.client.Do(req) if err != nil { @@ -99,6 +102,9 @@ func (d *DiagnosticsCollector) Flush() error { func (d *DiagnosticsCollector) CheckVersion() error { var rsp versionResponse req, err := http.NewRequest("GET", d.VersionURL, nil) + if err != nil { + return errors.Wrap(err, "making request") + } resp, err := d.client.Do(req) if err != nil { return errors.Wrap(err, "getting version") diff --git a/handler_test.go b/handler_test.go index 2d438e72a..9e947805c 100644 --- a/handler_test.go +++ b/handler_test.go @@ -1076,6 +1076,9 @@ func TestHandler_Frame_GetFields(t *testing.T) { t.Run("ErrFrameFieldNotAllowed", func(t *testing.T) { idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) _, err := idx.CreateFrameIfNotExists("f1", pilosa.FrameOptions{}) + if err != nil { + t.Fatalf("creating frame: %v", err) + } resp, err := http.Get(s.URL + "/index/i/frame/f1/fields") if err != nil { diff --git a/index_test.go b/index_test.go index ac90d0ac7..a83fb7609 100644 --- a/index_test.go +++ b/index_test.go @@ -249,6 +249,9 @@ func TestIndex_InvalidName(t *testing.T) { panic(err) } index, err := pilosa.NewIndex(path, "ABC") + if err == nil { + t.Fatalf("should have gotten an error on index name with caps") + } if index != nil { t.Fatalf("unexpected index name %v", index) } From 0e38eae6e379c94e9d08f49d0f961c83be4f0849 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 10:45:58 -0500 Subject: [PATCH 08/15] convert time.Now().Sub() to time.Since() --- cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.go b/cache.go index e27d2f93c..a59397c4e 100644 --- a/cache.go +++ b/cache.go @@ -233,7 +233,7 @@ func (c *RankCache) Recalculate() { func (c *RankCache) invalidate() { // Don't invalidate more than once every X seconds. // TODO: consider making this configurable. - if time.Now().Sub(c.updateTime).Seconds() < 10 { + if time.Since(c.updateTime).Seconds() < 10 { return } c.stats.Count("cache.invalidate", 1, 1.0) From 68dec9c60a71bd2198cdd238114b65ed92a4f391 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 10:46:41 -0500 Subject: [PATCH 09/15] remove unnecessary capacity in make() --- cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.go b/cache.go index a59397c4e..6fc70dcaf 100644 --- a/cache.go +++ b/cache.go @@ -505,7 +505,7 @@ func NewNopCache() *NopCache { func (c *NopCache) Add(id uint64, n uint64) {} func (c *NopCache) BulkAdd(id uint64, n uint64) {} func (c *NopCache) Get(id uint64) uint64 { return 0 } -func (c *NopCache) IDs() []uint64 { return make([]uint64, 0, 0) } +func (c *NopCache) IDs() []uint64 { return make([]uint64, 0) } func (c *NopCache) Invalidate() {} func (c *NopCache) Len() int { return 0 } From a3445ec8842f31556984ecb1214044819eea80cd Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 10:48:40 -0500 Subject: [PATCH 10/15] simplify loops with append... in cluster.go --- cluster.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cluster.go b/cluster.go index c770eab98..033f8af41 100644 --- a/cluster.go +++ b/cluster.go @@ -622,9 +622,7 @@ type fragsByHost map[string][]frag func (a fragsByHost) add(b fragsByHost) fragsByHost { for k, v := range b { - for _, vv := range v { - a[k] = append(a[k], vv) - } + a[k] = append(a[k], v...) } return a } @@ -1175,9 +1173,7 @@ func (c *Cluster) generateResizeJobByAction(nodeAction nodeAction) (*ResizeJob, } for id, sources := range fragSources { - for _, src := range sources { - multiIndex[id] = append(multiIndex[id], src) - } + multiIndex[id] = append(multiIndex[id], sources...) } } From 652b5695e18cfe1a9bc1c824d88aeaab367eafe3 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 10:56:24 -0500 Subject: [PATCH 11/15] fix redundant arguments to make() calls --- executor.go | 4 ++-- fragment.go | 2 +- fragment_test.go | 8 ++++---- holder.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/executor.go b/executor.go index b6dc08d41..42fa52005 100644 --- a/executor.go +++ b/executor.go @@ -192,7 +192,7 @@ func (e *Executor) validateCallArgs(c *pql.Call) error { case []int64, []uint64: // noop case []interface{}: - b := make([]int64, len(v), len(v)) + b := make([]int64, len(v)) for i := range v { b[i] = v[i].(int64) } @@ -1554,7 +1554,7 @@ loop: // If a mapping of slices to a node fails then the slices are resplit across // secondary nodes and retried. This continues to occur until all nodes are exhausted. func (e *Executor) mapReduce(ctx context.Context, index string, slices []uint64, c *pql.Call, opt *ExecOptions, mapFn mapFunc, reduceFn reduceFunc) (interface{}, error) { - ch := make(chan mapResponse, 0) + ch := make(chan mapResponse) // Wrap context with a cancel to kill goroutines on exit. ctx, cancel := context.WithCancel(ctx) diff --git a/fragment.go b/fragment.go index 6b5021c99..2ce8eaca4 100644 --- a/fragment.go +++ b/fragment.go @@ -1013,7 +1013,7 @@ func (f *Fragment) Top(opt TopOptions) ([]Pair, error) { } //Pop first opt.N elements out of heap - r := make(Pairs, results.Len(), results.Len()) + r := make(Pairs, results.Len()) x := results.Len() i := 1 for results.Len() > 0 { diff --git a/fragment_test.go b/fragment_test.go index 64f70c14a..2f8c6e622 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -1179,8 +1179,8 @@ func BenchmarkFragment_FullSnapshot(b *testing.B) { // Generate some intersecting data. maxX := 1048576 / 2 sz := maxX - rows := make([]uint64, sz, sz) - cols := make([]uint64, sz, sz) + rows := make([]uint64, sz) + cols := make([]uint64, sz) max := 0 for row := 0; row < 100; row++ { @@ -1215,8 +1215,8 @@ func BenchmarkFragment_Import(b *testing.B) { defer f.Close() maxX := 1048576 * 5 * 2 sz := maxX - rows := make([]uint64, sz, sz) - cols := make([]uint64, sz, sz) + rows := make([]uint64, sz) + cols := make([]uint64, sz) i := 0 for row := 0; row < 100; row++ { val := 1 diff --git a/holder.go b/holder.go index a4a3ba59c..a80ba4539 100644 --- a/holder.go +++ b/holder.go @@ -75,7 +75,7 @@ type Holder struct { func NewHolder() *Holder { return &Holder{ indexes: make(map[string]*Index), - closing: make(chan struct{}, 0), + closing: make(chan struct{}), opened: make(chan struct{}), From a0f4c613a2de1a1ba78078f5ad941b5348761b59 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 10:58:33 -0500 Subject: [PATCH 12/15] remove uneccessary underscores when accessing map values --- executor.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/executor.go b/executor.go index 42fa52005..329a571aa 100644 --- a/executor.go +++ b/executor.go @@ -122,7 +122,7 @@ func (e *Executor) Execute(ctx context.Context, index string, q *pql.Query, slic for _, call := range q.Calls { if call.SupportsInverse() && needsSlices { // Fetch frame & row label based on argument. - frame, _ := call.Args["frame"].(string) + frame := call.Args["frame"].(string) if frame == "" { frame = DefaultFrame } @@ -206,9 +206,9 @@ func (e *Executor) validateCallArgs(c *pql.Call) error { // executeSum executes a Sum() call. func (e *Executor) executeSum(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (ValCount, error) { - if frame, _ := c.Args["frame"]; frame == "" { + if frame := c.Args["frame"]; frame == "" { return ValCount{}, errors.New("Sum(): frame required") - } else if field, _ := c.Args["field"]; field == "" { + } else if field := c.Args["field"]; field == "" { return ValCount{}, errors.New("Sum(): field required") } @@ -241,9 +241,9 @@ func (e *Executor) executeSum(ctx context.Context, index string, c *pql.Call, sl // executeFieldMin executes a Min() call. func (e *Executor) executeFieldMin(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (ValCount, error) { - if frame, _ := c.Args["frame"]; frame == "" { + if frame := c.Args["frame"]; frame == "" { return ValCount{}, errors.New("Min(): frame required") - } else if field, _ := c.Args["field"]; field == "" { + } else if field := c.Args["field"]; field == "" { return ValCount{}, errors.New("Min(): field required") } @@ -276,9 +276,9 @@ func (e *Executor) executeFieldMin(ctx context.Context, index string, c *pql.Cal // executeFieldMax executes a Max() call. func (e *Executor) executeFieldMax(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (ValCount, error) { - if frame, _ := c.Args["frame"]; frame == "" { + if frame := c.Args["frame"]; frame == "" { return ValCount{}, errors.New("Max(): frame required") - } else if field, _ := c.Args["field"]; field == "" { + } else if field := c.Args["field"]; field == "" { return ValCount{}, errors.New("Max(): field required") } From 620226d6ef42127fa3344f89a042d0ec4fadee1c Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 11:00:09 -0500 Subject: [PATCH 13/15] simplify comparisons to bool constants --- handler_test.go | 4 ++-- pilosa.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/handler_test.go b/handler_test.go index 9e947805c..0bb73db4a 100644 --- a/handler_test.go +++ b/handler_test.go @@ -492,7 +492,7 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) { t.Fatalf("unexpected attr[0]: %s=%v", k, v) } else if k, v := attrs[1].Key, attrs[1].IntValue; k != "c" || v != int64(1) { t.Fatalf("unexpected attr[1]: %s=%v", k, v) - } else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || v != true { + } else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || !v { t.Fatalf("unexpected attr[2]: %s=%v", k, v) } } @@ -551,7 +551,7 @@ func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) { t.Fatalf("unexpected attr[0]: %s=%v", k, v) } else if k, v := attrs[1].Key, attrs[1].IntValue; k != "c" || v != int64(1) { t.Fatalf("unexpected attr[1]: %s=%v", k, v) - } else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || v != true { + } else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || !v { t.Fatalf("unexpected attr[2]: %s=%v", k, v) } diff --git a/pilosa.go b/pilosa.go index f29356ef6..bad8badc3 100644 --- a/pilosa.go +++ b/pilosa.go @@ -111,7 +111,7 @@ const TimeFormat = "2006-01-02T15:04" // ValidateName ensures that the name is a valid format. func ValidateName(name string) error { - if nameRegexp.Match([]byte(name)) == false { + if !nameRegexp.Match([]byte(name)) { return ErrName } return nil From c54383193726234a1d2853da6ae0bc6ad312e9a7 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 11:02:50 -0500 Subject: [PATCH 14/15] remove unused code nodeByURI, deleteFrameFieldRequest, readColumnAttrSets, validOptions, defaultBody --- cluster.go | 10 ----- handler.go | 41 --------------------- handler_test.go | 98 ------------------------------------------------- 3 files changed, 149 deletions(-) diff --git a/cluster.go b/cluster.go index 033f8af41..97afa0eef 100644 --- a/cluster.go +++ b/cluster.go @@ -541,16 +541,6 @@ func (c *Cluster) nodeByID(id string) *Node { return nil } -// nodeByURI returns a node reference by node URI. -func (c *Cluster) nodeByURI(uri URI) *Node { - for _, n := range c.Nodes { - if n.URI == uri { - return n - } - } - return nil -} - // nodePositionByID returns the position of the node in slice c.Nodes. func (c *Cluster) nodePositionByID(nodeID string) int { for i, n := range c.Nodes { diff --git a/handler.go b/handler.go index 887e4e981..b9a9e1257 100644 --- a/handler.go +++ b/handler.go @@ -29,7 +29,6 @@ import ( "strconv" "strings" "time" - "unicode" "github.com/gogo/protobuf/proto" "github.com/gorilla/mux" @@ -683,8 +682,6 @@ type getFrameFieldsResponse struct { Fields []*Field `json:"fields,omitempty"` } -type deleteFrameFieldRequest struct{} - type deleteFrameFieldResponse struct{} // handleGetFrameViews handles GET /frame/views request. @@ -779,29 +776,6 @@ type postFrameAttrDiffResponse struct { Attrs map[uint64]map[string]interface{} `json:"attrs"` } -// readColumnAttrSets returns a list of column attribute objects by id. -func (h *Handler) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet, error) { - if index == nil { - return nil, nil - } - - a := make([]*ColumnAttrSet, 0, len(ids)) - for _, id := range ids { - // Read attributes for column. Skip column if empty. - attrs, err := index.ColumnAttrStore().Attrs(id) - if err != nil { - return nil, err - } else if len(attrs) == 0 { - continue - } - - // Append column with attributes. - a = append(a, &ColumnAttrSet{ID: id, Attrs: attrs}) - } - - return a, nil -} - // readQueryRequest parses an query parameters from r. func (h *Handler) readQueryRequest(r *http.Request) (*QueryRequest, error) { switch r.Header.Get("Content-Type") { @@ -855,21 +829,6 @@ func (h *Handler) readURLQueryRequest(r *http.Request) (*QueryRequest, error) { }, nil } -// validOptions return all attributes of an interface with lower first character. -func validOptions(v interface{}) map[string]bool { - validQuery := make(map[string]bool) - argsType := reflect.ValueOf(v).Type() - - for i := 0; i < argsType.NumField(); i++ { - fieldName := argsType.Field(i).Name - chars := []rune(fieldName) - chars[0] = unicode.ToLower(chars[0]) - fieldName = string(chars) - validQuery[fieldName] = true - } - return validQuery -} - // writeQueryResponse writes the response from the executor to w. func (h *Handler) writeQueryResponse(w http.ResponseWriter, r *http.Request, resp *QueryResponse) error { if strings.Contains(r.Header.Get("Accept"), "application/x-protobuf") { diff --git a/handler_test.go b/handler_test.go index 0bb73db4a..c5843617b 100644 --- a/handler_test.go +++ b/handler_test.go @@ -1225,104 +1225,6 @@ func TestHandler_Expvars(t *testing.T) { } } -var defaultBody = ` - { - "frames":[ - { - "name":"cab-type", - "options": { - "timeQuantum":"YMD", - "inverseEnabled":false, - "cacheType":"ranked" - } - }, - { - "name":"add-ons", - "options": { - "timeQuantum":"YMD", - "inverseEnabled":false, - "cacheType":"ranked" - } - }, - { - "name":"distance-miles", - "options": { - "timeQuantum":"YMD", - "cacheType":"ranked" - } - } - ], - "fields":[ - { - "name":"id", - "primaryKey":true - }, - { - "name":"cabType", - "actions":[ - { - "frame":"cab-type", - "valueDestination":"mapping", - "valueMap":{ - "green":1, - "yellow":2 - } - } - ] - }, - { - "name":"withPet", - "actions":[ - { - "frame":"add-ons", - "valueDestination":"single-row-boolean", - "rowID":100 - } - ] - }, - { - "name":"distanceMiles", - "actions":[ - { - "frame":"distance-miles", - "valueDestination":"value-to-row" - - } - ] - }, - { - "name":"noFrame", - "actions":[ - { - "frame":"foo", - "valueDestination":"value-to-row" - - } - ] - }, - { - "name":"null_value", - "actions":[ - { - "frame":"add-ons", - "valueDestination":"value-to-row" - - } - ] - }, - { - "name":"time_value", - "actions":[ - { - "frame":"add-ons", - "valueDestination":"set-timestamp" - - } - ] - } - ] - }` - func MustReadAll(r io.Reader) []byte { buf, err := ioutil.ReadAll(r) if err != nil { From 8ae170ac6c59ea2a1bf711ac3b6fc632dfe21190 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 15 May 2018 11:05:36 -0500 Subject: [PATCH 15/15] simplify regexes by using backquoted strings to avoid double escapes --- uri.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uri.go b/uri.go index 7ab606788..5d823d8b6 100644 --- a/uri.go +++ b/uri.go @@ -26,8 +26,8 @@ import ( ) var schemeRegexp = regexp.MustCompile("^[+a-z]+$") -var hostRegexp = regexp.MustCompile("^[0-9a-z.-]+$|^\\[[:0-9a-fA-F]+\\]$") -var addressRegexp = regexp.MustCompile("^(([+a-z]+):\\/\\/)?([0-9a-z.-]+|\\[[:0-9a-fA-F]+\\])?(:([0-9]+))?$") +var hostRegexp = regexp.MustCompile(`^[0-9a-z.-]+$|^\[[:0-9a-fA-F]+\]$`) +var addressRegexp = regexp.MustCompile(`^(([+a-z]+):\/\/)?([0-9a-z.-]+|\[[:0-9a-fA-F]+\])?(:([0-9]+))?$`) // URI represents a Pilosa URI. // A Pilosa URI consists of three parts: