From 7e1449e9a4b67dc9a8cdd5602c2dcd7215445d82 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Mon, 14 Nov 2022 22:09:21 +0100 Subject: [PATCH] Fix methods with no response value Fixes https://github.com/webrpc/webrpc/issues/74 Fixes https://github.com/webrpc/webrpc/issues/104 Fixes https://github.com/webrpc/webrpc/issues/105 --- _examples/golang-basics/example.gen.go | 1 + _examples/golang-imports/api.gen.go | 1 + server.go.tmpl | 2 ++ 3 files changed, 4 insertions(+) diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index dad6731..b83f9cd 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -224,6 +224,7 @@ func (s *exampleServiceServer) servePingJSON(ctx context.Context, w http.Respons w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) + w.Write([]byte("{}")) } func (s *exampleServiceServer) serveStatus(ctx context.Context, w http.ResponseWriter, r *http.Request) { diff --git a/_examples/golang-imports/api.gen.go b/_examples/golang-imports/api.gen.go index ef1583a..f4bf2ec 100644 --- a/_examples/golang-imports/api.gen.go +++ b/_examples/golang-imports/api.gen.go @@ -180,6 +180,7 @@ func (s *exampleAPIServer) servePingJSON(ctx context.Context, w http.ResponseWri w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) + w.Write([]byte("{}")) } func (s *exampleAPIServer) serveStatus(ctx context.Context, w http.ResponseWriter, r *http.Request) { diff --git a/server.go.tmpl b/server.go.tmpl index d6f1355..69e44b1 100644 --- a/server.go.tmpl +++ b/server.go.tmpl @@ -132,6 +132,8 @@ func (s *{{$serviceName}}) serve{{ .Name | firstLetterToUpper }}JSON(ctx context {{- if .Outputs | len}} w.Write(respBody) + {{- else }} + w.Write([]byte("{}")) {{- end}} } {{end}}