diff --git a/pkg/search/describe.go b/pkg/search/describe.go index e33a31155..f63f73839 100644 --- a/pkg/search/describe.go +++ b/pkg/search/describe.go @@ -39,13 +39,13 @@ import ( "perkeep.org/pkg/types/camtypes" ) -func (sh *Handler) serveDescribe(rw http.ResponseWriter, req *http.Request) { +func (h *Handler) serveDescribe(rw http.ResponseWriter, req *http.Request) { defer httputil.RecoverJSON(rw, req) var dr DescribeRequest dr.fromHTTP(req) ctx := context.TODO() - res, err := sh.Describe(ctx, &dr) + res, err := h.Describe(ctx, &dr) if err != nil { httputil.ServeJSONError(rw, err) return @@ -57,16 +57,16 @@ const verboseDescribe = false // Describe returns a response for the given describe request. It acquires RLock // on the Handler's index. -func (sh *Handler) Describe(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) { - sh.index.RLock() - defer sh.index.RUnlock() +func (h *Handler) Describe(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) { + h.index.RLock() + defer h.index.RUnlock() - return sh.DescribeLocked(ctx, dr) + return h.DescribeLocked(ctx, dr) } // DescribeLocked returns a response for the given describe request. It is the // caller's responsibility to lock the search handler's index. -func (sh *Handler) DescribeLocked(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) { +func (h *Handler) DescribeLocked(ctx context.Context, dr *DescribeRequest) (dres *DescribeResponse, err error) { if verboseDescribe { t0 := time.Now() defer func() { @@ -78,7 +78,7 @@ func (sh *Handler) DescribeLocked(ctx context.Context, dr *DescribeRequest) (dre log.Printf("Described %d blobs in %v", num, td) }() } - sh.initDescribeRequest(dr) + h.initDescribeRequest(dr) if dr.BlobRef.Valid() { dr.StartDescribe(ctx, dr.BlobRef, dr.depth()) } @@ -516,17 +516,17 @@ func (dp *DescribedPermanode) IsContainer() bool { // NewDescribeRequest returns a new DescribeRequest holding the state // of blobs and their summarized descriptions. Use DescribeBlob // one or more times before calling Result. -func (sh *Handler) NewDescribeRequest() *DescribeRequest { +func (h *Handler) NewDescribeRequest() *DescribeRequest { dr := new(DescribeRequest) - sh.initDescribeRequest(dr) + h.initDescribeRequest(dr) return dr } -func (sh *Handler) initDescribeRequest(req *DescribeRequest) { +func (h *Handler) initDescribeRequest(req *DescribeRequest) { if req.sh != nil { panic("already initialized") } - req.sh = sh + req.sh = h req.m = make(MetaMap) req.errs = make(map[string]error) req.wg = new(sync.WaitGroup) diff --git a/pkg/search/export_test.go b/pkg/search/export_test.go index 88fdf7dfd..1c2c3525d 100644 --- a/pkg/search/export_test.go +++ b/pkg/search/export_test.go @@ -34,15 +34,15 @@ func ExportSetExpandLocationHook(val bool) { expandLocationHook = val } func ExportBufferedConst() int { return buffered } -func (s *SearchQuery) ExportPlannedQuery() *SearchQuery { - return s.plannedQuery(nil) +func (q *SearchQuery) ExportPlannedQuery() *SearchQuery { + return q.plannedQuery(nil) } var SortName = sortName -func (s *Handler) ExportGetPermanodeLocation(ctx context.Context, permaNode blob.Ref, +func (h *Handler) ExportGetPermanodeLocation(ctx context.Context, permaNode blob.Ref, at time.Time) (camtypes.Location, error) { - return s.lh.PermanodeLocation(ctx, permaNode, at, s.owner) + return h.lh.PermanodeLocation(ctx, permaNode, at, h.owner) } func ExportBestByLocation(res *SearchResult, loc map[blob.Ref]camtypes.Location, limit int) { diff --git a/pkg/search/expr.go b/pkg/search/expr.go index 0703b0d32..d155f8056 100644 --- a/pkg/search/expr.go +++ b/pkg/search/expr.go @@ -189,19 +189,17 @@ func (p *parser) parseOrRHS(lhs *Constraint) (c *Constraint, err error) { } func (p *parser) parseAnd() (c *Constraint, err error) { - for { - c, err = p.parseOperand() - if err != nil { - return - } - switch p.peek().typ { - case tokenAnd: - p.next() - case tokenOr, tokenClose, tokenEOF: - return - } - return p.parseAndRHS(c) + c, err = p.parseOperand() + if err != nil { + return } + switch p.peek().typ { + case tokenAnd: + p.next() + case tokenOr, tokenClose, tokenEOF: + return + } + return p.parseAndRHS(c) } func (p *parser) parseAndRHS(lhs *Constraint) (c *Constraint, err error) { @@ -322,7 +320,7 @@ func (p *parser) parseAtom() (*Constraint, error) { } t := faultToken() err = newParseExpError(fmt.Sprintf("Unknown search predicate: %q", t.val), t) - log.Printf(err.Error()) + log.Printf("parsing search expression atom: %v", err) return nil, err } diff --git a/pkg/search/handler.go b/pkg/search/handler.go index b5d46164c..40a4026cb 100644 --- a/pkg/search/handler.go +++ b/pkg/search/handler.go @@ -951,11 +951,11 @@ func evalSearchInput(in string) (*Constraint, error) { } // getNamed displays the search expression or constraint json for the requested alias. -func (sh *Handler) getNamed(ctx context.Context, name string) (string, error) { - if sh.fetcher == nil { +func (h *Handler) getNamed(ctx context.Context, name string) (string, error) { + if h.fetcher == nil { return "", fmt.Errorf("GetNamed functionality not available") } - sr, err := sh.Query(ctx, NamedSearch(name)) + sr, err := h.Query(ctx, NamedSearch(name)) if err != nil { return "", err } @@ -970,7 +970,7 @@ func (sh *Handler) getNamed(ctx context.Context, name string) (string, error) { return "", fmt.Errorf("Invalid blob ref: %s", substRefS) } - reader, _, err := sh.fetcher.Fetch(ctx, br) + reader, _, err := h.fetcher.Fetch(ctx, br) if err != nil { return "", err } diff --git a/pkg/search/websocket.go b/pkg/search/websocket.go index 6bbde4ac0..2277f37d7 100644 --- a/pkg/search/websocket.go +++ b/pkg/search/websocket.go @@ -307,7 +307,7 @@ var upgrader = websocket.Upgrader{ // uses a default origin check policy } -func (sh *Handler) serveWebSocket(rw http.ResponseWriter, req *http.Request) { +func (h *Handler) serveWebSocket(rw http.ResponseWriter, req *http.Request) { ws, err := upgrader.Upgrade(rw, req, nil) if _, ok := err.(websocket.HandshakeError); ok { http.Error(rw, "Not a websocket handshake", http.StatusBadRequest) @@ -319,10 +319,10 @@ func (sh *Handler) serveWebSocket(rw http.ResponseWriter, req *http.Request) { c := &wsConn{ ws: ws, send: make(chan []byte, 256), - sh: sh, + sh: h, queries: make(map[string]*watchedQuery), } - sh.wsHub.register <- c + h.wsHub.register <- c go c.writePump() c.readPump() }