much better and easier to read code

This commit is contained in:
Jeff Carr 2025-09-08 22:43:12 -05:00
parent b9ec316d35
commit 7ea7393d6c
2 changed files with 14 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
"net/http" "net/http"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/httppb" "go.wit.com/lib/protobuf/httppb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -47,17 +46,13 @@ func sendPendingPatchsets(pb *forgepb.Patchsets, reqPB *httppb.HttpRequest) *for
return allPatchsetsPB return allPatchsetsPB
} }
func makeReposPB(reqPB *httppb.HttpRequest) (*gitpb.Repos, error) { /*
pb := gitpb.NewRepos()
err := pb.Unmarshal(reqPB.ServerData)
return pb, err
}
func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) { func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
pb := forgepb.NewPatches() pb := forgepb.NewPatches()
err := pb.Unmarshal(reqPB.ServerData) err := pb.Unmarshal(reqPB.ServerData)
return pb, err return pb, err
} }
*/
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) { func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) {
pb := forgepb.NewPatchsets() pb := forgepb.NewPatchsets()

20
http.go
View File

@ -51,7 +51,7 @@ func whoSent(r *http.Request) string {
func logReqPB(pb *httppb.HttpRequest) { func logReqPB(pb *httppb.HttpRequest) {
log.Info("LOG: httppb.HttpRequest START:") log.Info("LOG: httppb.HttpRequest START:")
for i, line := range pb.Log { for i, line := range pb.Log {
log.Infof("\t%d, URL:%s LINE: %s\n", int(i), pb.URL, line) log.Infof("%d, URL:%s LINE: %s\n", int(i), pb.URL, line)
} }
log.Info("LOG: httppb.HttpRequest END") log.Info("LOG: httppb.HttpRequest END")
} }
@ -76,12 +76,14 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
reqPB.Log = append(reqPB.Log, log.Sprintf("forged REQUEST URL =", requrl, "from =", who)) reqPB.Log = append(reqPB.Log, log.Sprintf("forged REQUEST URL=%s", requrl))
if strings.HasPrefix(route, "/repos/") { if strings.HasPrefix(route, "/repos/") {
pb, err := makeReposPB(reqPB) pb := gitpb.NewRepos()
if err != nil { if err := pb.Unmarshal(reqPB.ClientData); err == nil {
reqPB.Log = append(reqPB.Log, log.Sprintf("%v", err)) reqPB.Log = append(reqPB.Log, log.Sprintf("Repos Unmarshal() len=%d", pb.Len()))
} else {
reqPB.Log = append(reqPB.Log, log.Sprintf("Repos Unmarshal() err=%v", err))
} }
result := gitpb.NewRepos() result := gitpb.NewRepos()
switch route { switch route {
@ -105,9 +107,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
} }
if strings.HasPrefix(route, "/patches/") { if strings.HasPrefix(route, "/patches/") {
pb, err := makePatchesPB(reqPB) pb := forgepb.NewPatches()
if err != nil { if err := pb.Unmarshal(reqPB.ClientData); err == nil {
reqPB.Log = append(reqPB.Log, log.Sprintf("%v", err)) reqPB.Log = append(reqPB.Log, log.Sprintf("Patches Unmarshal() len=%d", pb.Len()))
} else {
reqPB.Log = append(reqPB.Log, log.Sprintf("Patches Unmarshal() err=%v", err))
} }
result := forgepb.NewPatches() result := forgepb.NewPatches()
switch route { switch route {