From 092495b2deb427773771c27f15295aef1b6e340d Mon Sep 17 00:00:00 2001 From: Jeffrey Picard Date: Mon, 24 May 2021 23:28:43 -0400 Subject: [PATCH] Handle name param and change flag parsing. --- dev.sh | 2 +- main.go | 24 ++++++++++++++++-------- protobuf/definitions/hub.proto | 2 +- protobuf/go/hub.pb.go | 10 +++++----- server/search.go | 4 ++++ server/server.go | 1 + 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dev.sh b/dev.sh index 98e2823..7f8aa52 100755 --- a/dev.sh +++ b/dev.sh @@ -3,4 +3,4 @@ hash reflex 2>/dev/null || go get github.com/cespare/reflex hash reflex 2>/dev/null || { echo >&2 'Make sure '"$(go env GOPATH)"'/bin is in your $PATH'; exit 1; } -reflex --decoration=none --start-service=true -- sh -c "go run . serve" +reflex --decoration=none --start-service=true -- sh -c "go run . -serve true" diff --git a/main.go b/main.go index 5624942..8705664 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "net" - "os" "time" pb "github.com/lbryio/hub/protobuf/go" @@ -38,7 +37,9 @@ func (c *loginCreds) RequireTransportSecurity() bool { func parseArgs(searchRequest *pb.SearchRequest) server.Args { + serve := flag.String("serve", "", "server client") query := flag.String("query", "", "query string") + name := flag.String("name", "", "name") claimType := flag.String("claimType", "", "claim type") id := flag.String("id", "", "_id") author := flag.String("author", "", "author") @@ -52,9 +53,17 @@ func parseArgs(searchRequest *pb.SearchRequest) server.Args { flag.Parse() + args := server.Args{Serve: false, Port: ":" + *port, User: *user, Pass: *pass} + + if *serve == "true" { + args.Serve = true + } if *query != "" { searchRequest.Query = *query } + if *name!= "" { + searchRequest.Name = []string{*name} + } if *claimType != "" { searchRequest.ClaimType = []string{*claimType} } @@ -75,7 +84,7 @@ func parseArgs(searchRequest *pb.SearchRequest) server.Args { } - return server.Args{Port: ":" + *port, User: *user, Pass: *pass} + return args } func parseServerArgs() server.Args { @@ -89,8 +98,11 @@ func parseServerArgs() server.Args { } func main() { - if len(os.Args) == 2 && os.Args[1] == "serve" { - args := parseServerArgs() + searchRequest := &pb.SearchRequest{} + + args := parseArgs(searchRequest) + + if args.Serve { l, err := net.Listen("tcp", args.Port) if err != nil { @@ -107,10 +119,6 @@ func main() { return } - searchRequest := &pb.SearchRequest{} - - args := parseArgs(searchRequest) - conn, err := grpc.Dial("localhost"+args.Port, grpc.WithInsecure(), //grpc.WithBlock(), diff --git a/protobuf/definitions/hub.proto b/protobuf/definitions/hub.proto index 6208395..abdb732 100644 --- a/protobuf/definitions/hub.proto +++ b/protobuf/definitions/hub.proto @@ -27,7 +27,7 @@ message RangeField { message SearchRequest { string query = 1; - string name = 2; + repeated string name = 2; int32 amount_order = 3; int32 limit = 4; repeated string order_by = 5; diff --git a/protobuf/go/hub.pb.go b/protobuf/go/hub.pb.go index 757745f..5f75a84 100644 --- a/protobuf/go/hub.pb.go +++ b/protobuf/go/hub.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0 -// protoc v3.17.0 +// protoc v3.17.1 // source: hub.proto package pb @@ -243,7 +243,7 @@ type SearchRequest struct { unknownFields protoimpl.UnknownFields Query string `protobuf:"bytes,1,opt,name=query,proto3" json:"query"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name"` + Name []string `protobuf:"bytes,2,rep,name=name,proto3" json:"name"` AmountOrder int32 `protobuf:"varint,3,opt,name=amount_order,json=amountOrder,proto3" json:"amount_order"` Limit int32 `protobuf:"varint,4,opt,name=limit,proto3" json:"limit"` OrderBy []string `protobuf:"bytes,5,rep,name=order_by,json=orderBy,proto3" json:"order_by"` @@ -340,11 +340,11 @@ func (x *SearchRequest) GetQuery() string { return "" } -func (x *SearchRequest) GetName() string { +func (x *SearchRequest) GetName() []string { if x != nil { return x.Name } - return "" + return nil } func (x *SearchRequest) GetAmountOrder() int32 { @@ -1234,7 +1234,7 @@ var file_hub_proto_rawDesc = []byte{ 0x06, 0x0a, 0x02, 0x47, 0x54, 0x10, 0x04, 0x22, 0xa9, 0x12, 0x0a, 0x0d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, diff --git a/server/search.go b/server/search.go index 1eb0027..cd75472 100644 --- a/server/search.go +++ b/server/search.go @@ -161,6 +161,10 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.SearchRe from = int(in.Offset) } + if len(in.Name) > 0 { + in.Normalized = in.Name + } + if len(in.OrderBy) > 0 { for _, x := range in.OrderBy { var toAppend string diff --git a/server/server.go b/server/server.go index 1d40d93..f011cfa 100644 --- a/server/server.go +++ b/server/server.go @@ -12,6 +12,7 @@ type Server struct { } type Args struct { + Serve bool Port string User string Pass string