-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
847 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: v1 | ||
plugins: | ||
- plugin: go | ||
out: . | ||
opt: | ||
- paths=source_relative | ||
- plugin: go-grpc | ||
out: . | ||
opt: | ||
- paths=source_relative | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: v1 | ||
breaking: | ||
use: | ||
- FILE | ||
lint: | ||
use: | ||
- DEFAULT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
proto "pathe.co/zinx/proto/gametake/v1" | ||
) | ||
|
||
var ( | ||
addr = flag.String("addr", "localhost:50051", "the address to connect to") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
log.Fatalf("did not connect: %v", err) | ||
} | ||
defer conn.Close() | ||
c := proto.NewGameTakeLearningClient(conn) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
r, err := c.GetHand(ctx, &proto.GametakeRequest{Id: "MyID"}) | ||
if err != nil { | ||
log.Fatalf("could not greet: %v", err) | ||
} | ||
log.Printf("Greeting: %s", r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
|
||
"google.golang.org/grpc" | ||
"pathe.co/zinx/pkg/game" | ||
proto "pathe.co/zinx/proto/gametake/v1" | ||
) | ||
|
||
var ( | ||
port = flag.Int("port", 50051, "The server port") | ||
) | ||
|
||
type server struct { | ||
proto.UnimplementedGameTakeLearningServer | ||
} | ||
|
||
func (s *server) GetHand(ctx context.Context, in *proto.GametakeRequest) (*proto.GametakeResponse, error) { | ||
log.Printf("Received: %v", in.GetId()) | ||
game := game.NewGame() | ||
cards := []*proto.Card{} | ||
for _, c := range game.Cartes[0:5] { | ||
card := proto.Card{Type: c.Genre, Color: c.Couleur} | ||
cards = append(cards, &card) | ||
} | ||
|
||
return &proto.GametakeResponse{Cards: cards}, nil | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) | ||
if err != nil { | ||
log.Fatalf("failed to listen: %v", err) | ||
} | ||
s := grpc.NewServer() | ||
proto.RegisterGameTakeLearningServer(s, &server{}) | ||
log.Printf("server listening at %v", lis.Addr()) | ||
if err := s.Serve(lis); err != nil { | ||
log.Fatalf("failed to serve: %v", err) | ||
} | ||
} |
Oops, something went wrong.