much better standard autogen code

This commit is contained in:
Jeff Carr 2025-09-08 04:34:43 -05:00
parent 96cd7ffb2d
commit da3244d265
1 changed files with 19 additions and 0 deletions

View File

@ -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.")