summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generateHTTP.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/generateHTTP.go b/generateHTTP.go
index 9cb53b3..0bf3b12 100644
--- a/generateHTTP.go
+++ b/generateHTTP.go
@@ -110,6 +110,25 @@ func httpSendReply(w io.Writer, FRUITS string) {
}
func httpCustom(w io.Writer, FRUITS string, fRUITS string, FRUIT string) {
+ fmt.Fprintln(w, "// Marshal protobuf, then http POST, then Unmarshal() to protobuf again")
+ fmt.Fprintln(w, "func (p *"+FRUITS+") HttpPost(baseURL string, route string) (*"+FRUITS+", *httppb.HttpRequest, error) {")
+ fmt.Fprintln(w, " data, err := p.Marshal()")
+ fmt.Fprintln(w, " if err != nil {")
+ fmt.Fprintln(w, " return nil, nil, err")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " reqPB, err := httppb.DoPost(baseURL, route, data)")
+ fmt.Fprintln(w, " if reqPB == nil {")
+ fmt.Fprintln(w, " return nil, nil, err")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " newpb := New"+FRUITS+"()")
+ fmt.Fprintln(w, " err = newpb.Unmarshal(reqPB.Body)")
+ fmt.Fprintln(w, " return newpb, reqPB, err")
+ fmt.Fprintln(w, "}")
+}
+
+func httpCustomOld(w io.Writer, FRUITS string, fRUITS string, FRUIT string) {
fmt.Fprintln(w, "// err handling here isn't great")
fmt.Fprintln(w, "func (p *"+FRUITS+") HttpPost(baseURL string, route string) (*"+FRUITS+", *httppb.HttpRequest, error) {")
fmt.Fprintln(w, " // if you ever have 'http://www.wit.com//' GO will regect the server recieving it.")