SDK StillDeep — Client Go

Client Go : protoc-gen-go-grpc, génération du code, premier panier.

Prerequis

  • Go 1.23+
  • protoc 25+
  • Plugins : protoc-gen-go, protoc-gen-go-grpc
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

Setup

mkdir my-pos-client && cd my-pos-client
go mod init example.com/my-pos-client
go get google.golang.org/grpc google.golang.org/protobuf

cp -r ../waxpos/src/public/StillDeep.Intelligence.Contracts/protos ./protos
mkdir -p generated

protoc \
  --proto_path=./protos \
  --go_out=./generated \
  --go_opt=paths=source_relative \
  --go-grpc_out=./generated \
  --go-grpc_opt=paths=source_relative \
  ./protos/common.proto ./protos/sales.proto ./protos/catalog.proto \
  ./protos/member.proto ./protos/device.proto ./protos/events.proto

Exemple

package main

import (
    "context"
    "log"

    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"

    pb "example.com/my-pos-client/generated"
)

func main() {
    conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil { log.Fatal(err) }
    defer conn.Close()

    client := pb.NewSalesServiceClient(conn)
    cart, err := client.CreateCart(context.Background(), &pb.CreateCartRequest{
        PostId: "post-1", CashierUserId: "user-1", IdempotencyKey: "key-1",
    })
    if err != nil { log.Fatal(err) }
    log.Printf("%+v", cart)
}