github.com/tsuna/gohbase@v0.0.0-20250731002811-4ffcadfba63e/hrpc/list.go (about) 1 package hrpc 2 3 import ( 4 "context" 5 "errors" 6 7 "github.com/tsuna/gohbase/pb" 8 "google.golang.org/protobuf/proto" 9 ) 10 11 // ListTableNames models a ListTableNames pb call 12 type ListTableNames struct { 13 base 14 regex string 15 includeSysTables bool 16 namespace string 17 } 18 19 // ListRegex sets a regex for ListTableNames 20 func ListRegex(regex string) func(Call) error { 21 return func(c Call) error { 22 l, ok := c.(*ListTableNames) 23 if !ok { 24 return errors.New("ListRegex option can only be used with ListTableNames") 25 } 26 l.regex = regex 27 return nil 28 } 29 } 30 31 // ListNamespace sets a namespace for ListTableNames 32 func ListNamespace(ns string) func(Call) error { 33 return func(c Call) error { 34 l, ok := c.(*ListTableNames) 35 if !ok { 36 return errors.New("ListNamespace option can only be used with ListTableNames") 37 } 38 l.namespace = ns 39 return nil 40 } 41 } 42 43 // ListSysTables includes sys tables for ListTableNames 44 func ListSysTables(b bool) func(Call) error { 45 return func(c Call) error { 46 l, ok := c.(*ListTableNames) 47 if !ok { 48 return errors.New("ListSysTables option can only be used with ListTableNames") 49 } 50 l.includeSysTables = b 51 return nil 52 } 53 } 54 55 // NewListTableNames creates a new GetTableNames request that will list tables in hbase. 56 // 57 // By default, matches all tables. Use the options (ListRegex, ListNamespace, ListSysTables) to 58 // set non default behaviour. 59 func NewListTableNames(ctx context.Context, opts ...func(Call) error) (*ListTableNames, error) { 60 tn := &ListTableNames{ 61 base: base{ 62 ctx: ctx, 63 resultch: make(chan RPCResult, 1), 64 }, 65 regex: ".*", 66 } 67 if err := applyOptions(tn, opts...); err != nil { 68 return nil, err 69 } 70 return tn, nil 71 } 72 73 // Name returns the name of this RPC call. 74 func (tn *ListTableNames) Name() string { 75 return "GetTableNames" 76 } 77 78 // Description returns the description of this RPC call. 79 func (tn *ListTableNames) Description() string { 80 return tn.Name() 81 } 82 83 // ToProto converts the RPC into a protobuf message. 84 func (tn *ListTableNames) ToProto() proto.Message { 85 return &pb.GetTableNamesRequest{ 86 Regex: proto.String(tn.regex), 87 IncludeSysTables: proto.Bool(tn.includeSysTables), 88 Namespace: proto.String(tn.namespace), 89 } 90 } 91 92 // NewResponse creates an empty protobuf message to read the response of this 93 // RPC. 94 func (tn *ListTableNames) NewResponse() proto.Message { 95 return &pb.GetTableNamesResponse{} 96 }