Skip to content

Commit 277a87f

Browse files
committed
Improve and update the example
1 parent e140022 commit 277a87f

File tree

9 files changed

+42
-54
lines changed

9 files changed

+42
-54
lines changed

_examples/petStore/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ all:
22
@awk -F'[ :]' '!/^all:/ && /^([A-z_-]+):/ {print "make " $$1}' Makefile
33

44
generate:
5-
make -C ../../ install
6-
gospeak ./proto/api.go
5+
go generate ./...
76

87
run-server:
98
@echo "Running server. You can test it with:"

_examples/petStore/cmd/server/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"log"
87
"net/http"
98

@@ -24,14 +23,16 @@ func main() {
2423
r.Handle("/*", proto.NewPetStoreServer(api))
2524

2625
log.Println("Serving PetStore API at :8080")
27-
http.ListenAndServe(":8080", r)
26+
if err := http.ListenAndServe(":8080", r); err != nil {
27+
log.Fatal(err)
28+
}
2829
}
2930

3031
func DebugPayload(next http.Handler) http.Handler {
3132
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3233
var bufReq, bufResp bytes.Buffer
3334

34-
r.Body = ioutil.NopCloser(io.TeeReader(r.Body, &bufReq))
35+
r.Body = io.NopCloser(io.TeeReader(r.Body, &bufReq))
3536
rw := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
3637
rw.Tee(&bufResp)
3738

_examples/petStore/go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/go-chi/chi/v5 v5.0.10
7-
github.com/golang-cz/gospeak v0.6.0
7+
github.com/golang-cz/gospeak v0.6.2
88
github.com/google/uuid v1.3.0
99
github.com/json-iterator/go v1.1.12
1010
github.com/stretchr/testify v1.8.1
@@ -31,7 +31,7 @@ require (
3131
github.com/sergi/go-diff v1.2.0 // indirect
3232
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
3333
github.com/src-d/gcfg v1.4.0 // indirect
34-
github.com/webrpc/webrpc v0.12.1-0.20230801165705-bbb62bb52b8f // indirect
34+
github.com/webrpc/webrpc v0.12.1 // indirect
3535
github.com/xanzy/ssh-agent v0.3.2 // indirect
3636
golang.org/x/crypto v0.11.0 // indirect
3737
golang.org/x/mod v0.12.0 // indirect
@@ -44,5 +44,3 @@ require (
4444
gopkg.in/warnings.v0 v0.1.2 // indirect
4545
gopkg.in/yaml.v3 v3.0.1 // indirect
4646
)
47-
48-
replace github.com/golang-cz/gospeak => ../../

_examples/petStore/go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ github.com/gliderlabs/ssh v0.1.3/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aev
1717
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
1818
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
1919
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
20+
github.com/golang-cz/gospeak v0.6.0/go.mod h1:Bkm3lL+H7zDuTDGRITvW909gwLtXsBT/WY5vkpb99zY=
21+
github.com/golang-cz/gospeak v0.6.1 h1:HWSho/4Xa+N1M7sD2O/s+qiw6TAiar1xbnr6KyfyTz4=
22+
github.com/golang-cz/gospeak v0.6.1/go.mod h1:Bkm3lL+H7zDuTDGRITvW909gwLtXsBT/WY5vkpb99zY=
23+
github.com/golang-cz/gospeak v0.6.2 h1:tdpcczFAnzppuRpq5LYv9VxolwlmAY5m7dVPwjqowOg=
24+
github.com/golang-cz/gospeak v0.6.2/go.mod h1:iCN0im0I9FBA+xLtVM1PUOH4bBEw4nmGFfFPoIhmfGY=
2025
github.com/golang-cz/textcase v1.2.0 h1:dX1cg09+7PLky8yUe9rYWa64epzW80TGiJYPz5vgxvM=
2126
github.com/golang-cz/textcase v1.2.0/go.mod h1:aWsQknYwxtTS2zSCrGGoRIsxmzjsHomRqLeMeVb+SKU=
2227
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -87,6 +92,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
8792
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
8893
github.com/webrpc/webrpc v0.12.1-0.20230801165705-bbb62bb52b8f h1:K5xCTeoVUTcl71hzTOnOIo5YckV3T+XtqcvCmE6JuaU=
8994
github.com/webrpc/webrpc v0.12.1-0.20230801165705-bbb62bb52b8f/go.mod h1:DwRj+2Vd0r4sanozfosHdv4RYi8kALVyVvpBPYqeGDQ=
95+
github.com/webrpc/webrpc v0.12.1 h1:L1PxRykmb6AyoOWjSsUjIhc3zwkAehx/DqGJ6nn0WUg=
96+
github.com/webrpc/webrpc v0.12.1/go.mod h1:DwRj+2Vd0r4sanozfosHdv4RYi8kALVyVvpBPYqeGDQ=
9097
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
9198
github.com/xanzy/ssh-agent v0.3.2 h1:eKj4SX2Fe7mui28ZgnFW5fmTz1EIr7ugo5s6wDxdHBM=
9299
github.com/xanzy/ssh-agent v0.3.2/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=

_examples/petStore/petstore.debug.gen.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@
647647
(*schema.TypeField)({
648648
Name: (string) (len=6) "status",
649649
Type: (*schema.VarType)({
650-
Expr: (string) (len=3) "int",
651-
Type: (schema.CoreType) 10,
650+
Expr: (string) (len=3) "any",
651+
Type: (schema.CoreType) 2,
652652
List: (*schema.VarListType)(<nil>),
653653
Map: (*schema.VarMapType)(<nil>),
654654
Struct: (*schema.VarStructType)(<nil>)
@@ -1230,8 +1230,8 @@
12301230
(*schema.TypeField)({
12311231
Name: (string) (len=6) "status",
12321232
Type: (*schema.VarType)({
1233-
Expr: (string) (len=3) "int",
1234-
Type: (schema.CoreType) 10,
1233+
Expr: (string) (len=3) "any",
1234+
Type: (schema.CoreType) 2,
12351235
List: (*schema.VarListType)(<nil>),
12361236
Map: (*schema.VarMapType)(<nil>),
12371237
Struct: (*schema.VarStructType)(<nil>)
@@ -1809,8 +1809,8 @@
18091809
(*schema.TypeField)({
18101810
Name: (string) (len=6) "status",
18111811
Type: (*schema.VarType)({
1812-
Expr: (string) (len=3) "int",
1813-
Type: (schema.CoreType) 10,
1812+
Expr: (string) (len=3) "any",
1813+
Type: (schema.CoreType) 2,
18141814
List: (*schema.VarListType)(<nil>),
18151815
Map: (*schema.VarMapType)(<nil>),
18161816
Struct: (*schema.VarStructType)(<nil>)
@@ -2434,8 +2434,8 @@
24342434
(*schema.TypeField)({
24352435
Name: (string) (len=6) "status",
24362436
Type: (*schema.VarType)({
2437-
Expr: (string) (len=3) "int",
2438-
Type: (schema.CoreType) 10,
2437+
Expr: (string) (len=3) "any",
2438+
Type: (schema.CoreType) 2,
24392439
List: (*schema.VarListType)(<nil>),
24402440
Map: (*schema.VarMapType)(<nil>),
24412441
Struct: (*schema.VarStructType)(<nil>)
@@ -3026,8 +3026,8 @@
30263026
(*schema.TypeField)({
30273027
Name: (string) (len=6) "status",
30283028
Type: (*schema.VarType)({
3029-
Expr: (string) (len=3) "int",
3030-
Type: (schema.CoreType) 10,
3029+
Expr: (string) (len=3) "any",
3030+
Type: (schema.CoreType) 2,
30313031
List: (*schema.VarListType)(<nil>),
30323032
Map: (*schema.VarMapType)(<nil>),
30333033
Struct: (*schema.VarStructType)(<nil>)
@@ -3629,8 +3629,8 @@
36293629
(*schema.TypeField)({
36303630
Name: (string) (len=6) "status",
36313631
Type: (*schema.VarType)({
3632-
Expr: (string) (len=3) "int",
3633-
Type: (schema.CoreType) 10,
3632+
Expr: (string) (len=3) "any",
3633+
Type: (schema.CoreType) 2,
36343634
List: (*schema.VarListType)(<nil>),
36353635
Map: (*schema.VarMapType)(<nil>),
36363636
Struct: (*schema.VarStructType)(<nil>)
@@ -4208,8 +4208,8 @@
42084208
(*schema.TypeField)({
42094209
Name: (string) (len=6) "status",
42104210
Type: (*schema.VarType)({
4211-
Expr: (string) (len=3) "int",
4212-
Type: (schema.CoreType) 10,
4211+
Expr: (string) (len=3) "any",
4212+
Type: (schema.CoreType) 2,
42134213
List: (*schema.VarListType)(<nil>),
42144214
Map: (*schema.VarMapType)(<nil>),
42154215
Struct: (*schema.VarStructType)(<nil>)
@@ -4252,7 +4252,7 @@
42524252
},
42534253
Deprecated_Messages: ([]interface {}) <nil>
42544254
}),
4255-
SchemaHash: (string) (len=40) "204f6b26587305ef3a4c043b8636035ada3889ef",
4255+
SchemaHash: (string) (len=40) "bc743e01dd79d6a627daf7f036d1a798fab4055f",
42564256
WebrpcGenVersion: (string) (len=11) "v0.13.0-dev",
42574257
WebrpcGenCommand: (string) (len=22) "gospeak ./proto/api.go",
42584258
WebrpcTarget: (string) (len=5) "debug",

_examples/petStore/petstore.gen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
},
224224
{
225225
"name": "status",
226-
"type": "int",
226+
"type": "any",
227227
"meta": [
228228
{
229229
"go.field.name": "Status"

_examples/petStore/proto/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
//go:webrpc json -out=./petstore.gen.json
1313
//go:webrpc debug -out=./petstore.debug.gen.txt
14-
//go:webrpc github.com/webrpc/gen-golang@tags/opts_types -server -pkg=proto -json=stdlib -types=false -legacyErrors=true -out=./server.gen.go
15-
//go:webrpc github.com/webrpc/gen-golang@tags/opts_types -client -pkg=client -json=stdlib -out=./client/petstore.gen.go
14+
//go:webrpc golang -server -pkg=proto -json=stdlib -types=false -legacyErrors=true -out=./server.gen.go
15+
//go:webrpc golang -client -pkg=client -json=stdlib -out=./client/petstore.gen.go
1616
//go:webrpc typescript -client -out=./client/petstore.gen.ts
1717
//go:webrpc json -out=./petstore.gen.json
1818
//go:webrpc openapi -out=./petstore.gen.yaml

_examples/petStore/proto/client/petstore.gen.go

Lines changed: 5 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/petStore/proto/server.gen.go

Lines changed: 5 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)