error out if server returns nil

This commit is contained in:
Jeff Carr 2025-09-22 08:52:33 -05:00
parent 6c9a3dd632
commit e9965f5109
2 changed files with 5 additions and 43 deletions

View File

@ -38,7 +38,6 @@ func (pb *Files) makeHTTPFile(pf *File) error {
}
}
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END HTTP\n")
return nil
}
@ -119,50 +118,12 @@ func httpPost(w io.Writer, FRUITS string, fRUITS string) {
fmt.Fprintln(w, " return nil, nil, err")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " if len(reqPB.ServerData) == 0 {")
fmt.Fprintln(w, " return nil, reqPB, fmt.Errorf(\"server returned len(data)=0\")")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " newpb := new("+FRUITS+")")
fmt.Fprintln(w, " err = newpb.Unmarshal(reqPB.ServerData)")
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.")
fmt.Fprintln(w, " // Even though the linux kernel gets the network payload")
fmt.Fprintln(w, " // also it never gives you an error about that, it just goes away invisably inside GO")
fmt.Fprintln(w, " tmpURL, _ := url.Parse(baseURL) // 'http://forge.grid.wit.com:2520')")
fmt.Fprintln(w, " finalURL := tmpURL.JoinPath(\"/"+fRUITS+"/\", route)")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " data, _ := p.Marshal()")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " var err error")
fmt.Fprintln(w, " var req *http.Request")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " req, err = http.NewRequest(http.MethodPost, finalURL.String(), bytes.NewBuffer(data))")
fmt.Fprintln(w, " if req == nil {")
fmt.Fprintln(w, " return nil, nil, err")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " usr, _ := user.Current()")
fmt.Fprintln(w, " req.Header.Set(\"author\", usr.Username)")
fmt.Fprintln(w, " hostname, _ := os.Hostname()")
fmt.Fprintln(w, " req.Header.Set(\"hostname\", hostname)")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " newdata, err := httppb.PostReq(req)")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " reqPB, err2 := httppb.ReqToPB(req)")
fmt.Fprintln(w, " reqPB.URL = finalURL.String()")
fmt.Fprintln(w, " if err != nil {")
fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, fmt.Sprintf(err))")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " if err2 != nil {")
fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, fmt.Sprintf(err2))")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " newpb := New"+FRUITS+"()")
fmt.Fprintln(w, " err = newpb.Unmarshal(newdata)")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " return newpb, reqPB, err")
fmt.Fprintln(w, "}")
}

View File

@ -197,6 +197,7 @@ func (pf *File) parseForMessage(line string) *MsgName {
log.Info("got autogenpb:http")
pf.DoHTTP = true
msg.DoHTTP = true
msg.DoMarshal = true // http requires Marshal
}
if strings.Contains(line, "`autogenpb:gui") {
log.Info("got autogenpb:gui")