Beispiel #1
0
func main() {
	log.SetFlags(log.Lshortfile | log.Ltime)
	flag.Parse()
	conn, err := grpc.Dial(*addr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Unable to dial server: %v", err)
	}
	client := storage.NewKeyValClient(conn)
	switch {
	case *key != "" && *val != "":
		_, err := client.Put(context.Background(), &storage.PutRequest{Element: &storage.Element{Key: *key, Val: *val}})
		if err != nil {
			log.Fatalf("Unable to put: %v", err)
		}
	case *key != "":
		reply, err := client.Get(context.Background(), &storage.GetRequest{Key: *key})
		if err != nil {
			log.Fatalf("Unable to get: %v", err)
		}
		log.Printf("Got: %v", reply)

	case *prefix != "":
		var cur string
		for {
			reply, err := client.Range(context.Background(), &storage.RangeRequest{Start: cur, Prefix: *prefix, Count: 2})
			if err != nil {
				log.Fatalf("Unable to range: %v", err)
			}
			if len(reply.Elements) == 0 {
				break
			}
			for _, e := range reply.Elements {
				log.Printf("%v", e)
			}
			cur = reply.Elements[len(reply.Elements)-1].Key
		}

	default:
		log.Fatalf("FAIL")
	}
}
Beispiel #2
0
func main() {
	log.SetFlags(log.Lshortfile | log.Ltime)
	flag.Parse()

	pConn, err := grpc.Dial(*pAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Unable to dial processor: %v", err)
	}
	pClient := processor.NewProcessClient(pConn)

	sConn, err := grpc.Dial(*sAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Unable to dial store: %v", err)
	}
	sClient := storage.NewKeyValClient(sConn)

	s := &server{
		proc:  pClient,
		store: sClient,
	}
	log.Fatalf("%v", http.ListenAndServe(fmt.Sprintf(":%d", *port), s))
}
Beispiel #3
0
func main() {
	log.SetFlags(log.Lshortfile | log.Ltime)
	flag.Parse()
	data, err := ioutil.ReadFile(*path)
	if err != nil {
		log.Fatalf("Unable to read %q: %v", *path, err)
	}

	pConn, err := grpc.Dial(*pAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Unable to dial processor: %v", err)
	}
	pClient := processor.NewProcessClient(pConn)

	sConn, err := grpc.Dial(*sAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Unable to dial store: %v", err)
	}
	sClient := storage.NewKeyValClient(sConn)

	pReply, err := pClient.Process(context.Background(), &processor.ProcessRequest{Image: string(data)})
	if err != nil {
		log.Fatalf("Unablet to process image: %v", err)
	}
	log.Printf("Id: %s", pReply.Id)

	for {
		time.Sleep(100 * time.Millisecond)
		sReply, err := sClient.Get(context.Background(), &storage.GetRequest{Key: pReply.Id + "-done"})
		if err != nil {
			continue
		}
		log.Printf("Success!")
		ioutil.WriteFile("out.png", []byte(sReply.Element.Val), 0777)
		break
	}
}