Claim search port #5

Merged
jeffreypicard merged 32 commits from claim_search_port into master 2021-06-23 17:07:41 +02:00
6 changed files with 28 additions and 15 deletions
Showing only changes of commit 092495b2de - Show all commits

2
dev.sh
View file

@ -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"

24
main.go
View file

@ -6,7 +6,6 @@ import (
"fmt"
lyoshenka commented 2021-06-15 22:14:43 +02:00 (Migrated from github.com)
Review

plz sort imports like this

builtins

everything from lbryio 

everything else
plz sort imports like this ``` builtins everything from lbryio everything else ```
"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(),

View file

@ -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;

View file

@ -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,

View file

@ -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

View file

@ -12,6 +12,7 @@ type Server struct {
}
type Args struct {
Serve bool
Port string
User string
Pass string