Compare commits

..

No commits in common. "master" and "v0.5.5" have entirely different histories.

3 changed files with 45 additions and 7 deletions

View File

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

View File

@ -38,6 +38,7 @@ func (pb *Files) makeHTTPFile(pf *File) error {
}
}
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END HTTP\n")
return nil
}
@ -118,12 +119,50 @@ 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,7 +197,6 @@ 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")