Skip to content

Commit 41aab6a

Browse files
committed
doc: update the usage in README
1 parent 56fe45b commit 41aab6a

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,78 @@ Cloud Run API Emulator provides application developers with a locally-running, e
66

77
## Usage
88

9-
TBW
9+
Run cloud-run-api-emulator by using docker like below:
10+
11+
```
12+
$ docker run --publish 8000:8000 --detach ghcr.io/kauche/cloud-run-api-emulator:0.0.1
13+
```
14+
15+
And then, you can use the emulator through a gRPC client like below:
16+
17+
(The example below is written in Go, but you can use any language.)
18+
19+
```go
20+
package main
21+
22+
import (
23+
"context"
24+
"fmt"
25+
"os"
26+
27+
"cloud.google.com/go/run/apiv2/runpb"
28+
"google.golang.org/grpc"
29+
"google.golang.org/grpc/credentials/insecure"
30+
)
31+
32+
func main() {
33+
ctx := context.Background()
34+
35+
cc, err := grpc.DialContext(ctx, "localhost:8000", grpc.WithTransportCredentials(insecure.NewCredentials()))
36+
if err != nil {
37+
fmt.Fprintf(os.Stderr, "failed to connect to the emulator: %s\n", err)
38+
os.Exit(1)
39+
}
40+
defer func() {
41+
if err = cc.Close(); err != nil {
42+
fmt.Fprintf(os.Stderr, "failed to close the connection: %s\n", err)
43+
os.Exit(1)
44+
}
45+
}()
46+
47+
client := runpb.NewServicesClient(cc)
48+
49+
createReq := &runpb.CreateServiceRequest{
50+
Parent: "projects/test-project/locations/us-central1",
51+
ServiceId: "my-service",
52+
Service: &runpb.Service{
53+
Description: "my service",
54+
},
55+
}
56+
57+
_, err = client.CreateService(ctx, createReq)
58+
if err != nil {
59+
fmt.Fprintf(os.Stderr, "failed to create the service: %s\n", err)
60+
os.Exit(1)
61+
}
62+
63+
listReq := &runpb.ListServicesRequest{
64+
Parent: "projects/test-project/locations/us-central1",
65+
PageSize: 5,
66+
}
67+
68+
listRes, err := client.ListServices(ctx, listReq)
69+
if err != nil {
70+
fmt.Fprintf(os.Stderr, "failed to list services: %s\n", err)
71+
os.Exit(1)
72+
}
73+
74+
// this prints `service: projects/test-project/locations/us-central1/services/my-service`
75+
for _, service := range listRes.Services {
76+
fmt.Printf("service: %s\n", service.Name)
77+
}
78+
}
79+
80+
```
1081

1182
## Supported Methods
1283

0 commit comments

Comments
 (0)