summaryrefslogtreecommitdiff
path: root/patchset.http.go
diff options
context:
space:
mode:
Diffstat (limited to 'patchset.http.go')
-rw-r--r--patchset.http.go30
1 files changed, 29 insertions, 1 deletions
diff --git a/patchset.http.go b/patchset.http.go
index 63b73b1..5e33a6f 100644
--- a/patchset.http.go
+++ b/patchset.http.go
@@ -9,6 +9,7 @@ import (
"os"
"os/user"
+ "go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
)
@@ -18,6 +19,10 @@ func (p *Patches) HttpPostVerbose(baseURL string, route string) (*Patches, error
}
func (p *Patches) HttpPost(baseURL string, route string) (*Patches, error) {
+ if p == nil {
+ log.Info("can't post a nil PB")
+ return nil, log.Errorf("can't post a nil PB")
+ }
// if you ever have "http://www.wit.com//" GO will regect the server recieving it.
// Even though the linux kernel gets the network payload
// also it never gives you an error about that, it just goes away invisably inside GO
@@ -45,7 +50,14 @@ func (p *Patches) HttpPost(baseURL string, route string) (*Patches, error) {
newpb := NewPatches()
err = newpb.Unmarshal(newdata)
- log.Infof("patchset PB HttpPost %s sent len(%d) got len(%d)\n", finalURL.String(), p.Len(), newpb.Len())
+ if newpb == nil {
+ log.Info("HttpPost() newpb WAS NIL")
+ }
+ if err != nil {
+ log.Info("HttpPost() err =", err)
+ } else {
+ log.Infof("patchset PB HttpPost %s sent len(%d) got len(%d)\n", finalURL.String(), p.Len(), newpb.Len())
+ }
return newpb, err
}
@@ -81,6 +93,22 @@ func (p *Patchset) HttpPost(baseURL string, route string) (*Patchset, error) {
return newpb, err
}
+func (p *Patches) SendReply(w http.ResponseWriter, reqPB *httppb.HttpRequest) error {
+ data, err := p.Marshal()
+ if err != nil {
+ reqPB.Errors = append(reqPB.Errors, log.Sprintf("%v", err))
+ }
+ if len(data) == 0 {
+ reqPB.Errors = append(reqPB.Errors, "Patches PB data was nil/emtpy without Marsha() error")
+ return nil
+ }
+ i, err := w.Write(data)
+ if err != nil {
+ reqPB.Errors = append(reqPB.Errors, log.Sprintf("i=%d %v", i, err))
+ }
+ return err
+}
+
func (p *Patchsets) HttpPostVerbose(baseURL string, route string) (*Patchsets, error) {
p.PrintTable()
return p.HttpPost(baseURL, route)