summaryrefslogtreecommitdiff
path: root/generateHTTP.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-08 04:02:50 -0500
committerJeff Carr <[email protected]>2025-09-08 04:02:50 -0500
commit96cd7ffb2d219e0afe1079583d4667e75e0c7642 (patch)
tree5484a5a625a7c61da71067b4ee7a27cc30951bf4 /generateHTTP.go
parent1fe6c532674ad10cbd5021a619fa0a269fe33194 (diff)
basic http functions
Diffstat (limited to 'generateHTTP.go')
-rw-r--r--generateHTTP.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/generateHTTP.go b/generateHTTP.go
index ef6ea0e..9cb53b3 100644
--- a/generateHTTP.go
+++ b/generateHTTP.go
@@ -36,6 +36,7 @@ func (pb *Files) makeHTTPFile(pf *File) error {
FRUITS := msg.Name
FRUIT := msg.GuiVarName
// fruitVars := color.Vars
+ httpSendReply(newf, FRUITS)
httpCustom(newf, FRUITS, FRUIT, FRUIT)
log.Printf("NEED TO ADD GUI FOR %s with var %s and found msg struct %s\n", msg.Name, msg.GuiVarName, color.Lockname)
}
@@ -90,21 +91,38 @@ func httpTest(w io.Writer, FRUITS string, fRUITS string, FRUIT string, fRUIT str
fmt.Fprintln(w, "// END TABLE UPDATE")
}
+func httpSendReply(w io.Writer, FRUITS string) {
+ fmt.Fprintln(w, "func (p *"+FRUITS+") SendReply(w http.ResponseWriter, reqPB *httppb.HttpRequest) error {")
+ fmt.Fprintln(w, " data, err := p.Marshal()")
+ fmt.Fprintln(w, " if err != nil {")
+ fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, log.Sprintf(, err))")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " if len(data) == 0 {")
+ fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, \"Patches PB data was nil/emtpy without Marsha() error\")")
+ fmt.Fprintln(w, " return nil")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " _, err = w.Write(data)")
+ fmt.Fprintln(w, " if err != nil {")
+ fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, log.Sprintf(, i, err))")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " return err")
+ fmt.Fprintln(w, "}")
+}
+
func httpCustom(w io.Writer, FRUITS string, fRUITS string, FRUIT string) {
fmt.Fprintln(w, "// err handling here isn't great")
- fmt.Fprintln(w, "func (p *Repos) HttpPost(baseURL string, route string) (*Repos, *httppb.HttpRequest, error) {")
+ 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(\"/repos/\", route)")
+ 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, " log.Info(\"reposs PB HttpPost\", finalURL.String())")
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")
@@ -126,10 +144,9 @@ func httpCustom(w io.Writer, FRUITS string, fRUITS string, FRUIT string) {
fmt.Fprintln(w, " // reqPB.Errors = append(reqPB.Errors, fmt.Sprintf(err2))")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, " newpb := NewRepos()")
+ fmt.Fprintln(w, " newpb := New"+FRUITS+"()")
fmt.Fprintln(w, " err = newpb.Unmarshal(newdata)")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, " // log.Info(repos PB HttpPost finalURL.String(), p.Len(), newpb.Len())")
fmt.Fprintln(w, " return newpb, reqPB, err")
fmt.Fprintln(w, "}")
}