summaryrefslogtreecommitdiff
path: root/handlePatches.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-05 07:09:47 -0500
committerJeff Carr <[email protected]>2025-09-05 07:24:24 -0500
commitb2af891b203ba28b74dc703e423fc7691cb3a3f1 (patch)
tree411250f05e0a257da9e71e74e7e32f7cfa4cbdc6 /handlePatches.go
parent1442d4f6c5b2940a1bafd0fe05fe5bed32015344 (diff)
builds. puts http headers in protobufv0.0.21
Diffstat (limited to 'handlePatches.go')
-rw-r--r--handlePatches.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/handlePatches.go b/handlePatches.go
new file mode 100644
index 0000000..904da49
--- /dev/null
+++ b/handlePatches.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "io/ioutil"
+ "net/http"
+ "strings"
+
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+)
+
+func handlePatches(w http.ResponseWriter, r *http.Request) error {
+ pb, err := marshalPatchesPB(r)
+ if err != nil {
+ return sendPatchesError(w, pb, err)
+ }
+
+ route := pb.HttpRequest.Route
+ if strings.HasPrefix(route, "/patches/old") {
+ processPatchesPB(r, pb)
+ } else if strings.HasPrefix(route, "/patches/old") {
+ log.Info("add new patches")
+ } else {
+ log.Info("unknown route", route)
+ }
+
+ return nil
+}
+
+func sendPatchesError(w http.ResponseWriter, r *forgepb.Patches, err error) error {
+ log.Info("send error back to user", err)
+ return nil
+}
+
+func processPatchesPB(r *http.Request, pb *forgepb.Patches) error {
+ log.Info("send error back to user")
+ return nil
+}
+
+func marshalPatchesPB(r *http.Request) (*forgepb.Patches, error) {
+ pb := forgepb.NewPatches()
+ msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
+ defer r.Body.Close()
+ if err != nil {
+ return pb, err
+ }
+
+ if err := pb.Unmarshal(msg); err != nil {
+ log.Info("proto.Unmarshal() failed on wire message len", len(msg), err)
+ // add the header
+ pb.AddHttpToPB(r)
+ return pb, err
+ }
+ // add the header
+ pb.AddHttpToPB(r)
+ return pb, nil
+}