Compare commits

..

3 Commits

Author SHA1 Message Date
Jeff Carr e9965f5109 error out if server returns nil 2025-09-22 08:52:33 -05:00
Jeff Carr 6c9a3dd632 http needs Marshal() 2025-09-22 08:50:37 -05:00
Jeff Carr 3a13970536 actually test http 2025-09-22 08:48:06 -05:00
3 changed files with 7 additions and 45 deletions

View File

@ -55,7 +55,7 @@ message Basket { // `autogenpb:nomutex`
repeated Apple stacks = 6; repeated Apple stacks = 6;
} }
// "Fruit" must exist. you can put anything in it // "Fruit" must exist. you can put anything in it
message Fruit { message Fruit { // `autogenpb:http` `autogenpb:marshal`
string brand = 1; // `autogenpb:unique` `autogenpb:sort` string brand = 1; // `autogenpb:unique` `autogenpb:sort`
Apple apples = 2; Apple apples = 2;
repeated Pear pears = 3; repeated Pear pears = 3;
@ -68,7 +68,7 @@ message Fruit {
} }
// "Fruits" MUST EXIST and start exactly this way // "Fruits" MUST EXIST and start exactly this way
// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto" // It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
message Fruits { // `autogenpb:marshal` `autogenpb:mutex` `autogenpb:gui` message Fruits { // `autogenpb:marshal` `autogenpb:mutex` `autogenpb:gui` `autogenpb:http`
string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079` string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
string version = 2; // `autogenpb:version:v0.0.1` string version = 2; // `autogenpb:version:v0.0.1`
repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s" repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s"

View File

@ -38,7 +38,6 @@ func (pb *Files) makeHTTPFile(pf *File) error {
} }
} }
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END HTTP\n") fmt.Fprintf(newf, "// END HTTP\n")
return nil 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, " return nil, nil, err")
fmt.Fprintln(w, " }") fmt.Fprintln(w, " }")
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, " newpb := new("+FRUITS+")")
fmt.Fprintln(w, " err = newpb.Unmarshal(reqPB.ServerData)") fmt.Fprintln(w, " err = newpb.Unmarshal(reqPB.ServerData)")
fmt.Fprintln(w, " return newpb, reqPB, err") fmt.Fprintln(w, " return newpb, reqPB, err")
fmt.Fprintln(w, "}") 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") log.Info("got autogenpb:http")
pf.DoHTTP = true pf.DoHTTP = true
msg.DoHTTP = true msg.DoHTTP = true
msg.DoMarshal = true // http requires Marshal
} }
if strings.Contains(line, "`autogenpb:gui") { if strings.Contains(line, "`autogenpb:gui") {
log.Info("got autogenpb:gui") log.Info("got autogenpb:gui")