github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/teamsearch.go (about)

     1  // Copyright 2020 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  // RPC handlers for team search operations
     5  
     6  package service
     7  
     8  import (
     9  	"context"
    10  
    11  	"github.com/keybase/client/go/libkb"
    12  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    13  	"github.com/keybase/client/go/teams/opensearch"
    14  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    15  )
    16  
    17  type TeamSearchHandler struct {
    18  	*BaseHandler
    19  	libkb.Contextified
    20  }
    21  
    22  var _ keybase1.TeamsInterface = (*TeamsHandler)(nil)
    23  
    24  func newTeamSearchHandler(xp rpc.Transporter, g *libkb.GlobalContext) *TeamSearchHandler {
    25  	return &TeamSearchHandler{
    26  		BaseHandler:  NewBaseHandler(g, xp),
    27  		Contextified: libkb.NewContextified(g),
    28  	}
    29  }
    30  
    31  func (h *TeamSearchHandler) TeamSearch(ctx context.Context, arg keybase1.TeamSearchArg) (res keybase1.TeamSearchRes, err error) {
    32  	ctx = libkb.WithLogTag(ctx, "TS")
    33  	if err := assertLoggedIn(ctx, h.G()); err != nil {
    34  		return res, err
    35  	}
    36  
    37  	var hits []keybase1.TeamSearchItem
    38  	mctx := libkb.NewMetaContext(ctx, h.G())
    39  	if arg.UseRemote {
    40  		hits, err = opensearch.Remote(mctx, arg.Query, arg.Limit)
    41  	} else {
    42  		hits, err = opensearch.Local(mctx, arg.Query, arg.Limit)
    43  	}
    44  	if err != nil {
    45  		return res, err
    46  	}
    47  	res.Results = hits
    48  	return res, nil
    49  }