67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
"go.wit.com/lib/protobuf/httppb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
|
newPatchesPB := new(forgepb.Patches)
|
|
for newpatch := range pb.IterAll() {
|
|
me.forge.AddNewPatch(newpatch)
|
|
newPatchesPB.Append(newpatch)
|
|
}
|
|
reqPB.Logf("Recived %d patches from client", newPatchesPB.Len())
|
|
return newPatchesPB
|
|
}
|
|
|
|
func handleMergedPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
|
newPatchesPB := new(forgepb.Patches)
|
|
for newpatch := range pb.IterAll() {
|
|
if expirePatch(newpatch) {
|
|
newPatchesPB.Append(newpatch)
|
|
}
|
|
}
|
|
return newPatchesPB
|
|
}
|
|
|
|
func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
|
allPatchesPB := new(forgepb.Patches)
|
|
for pset := range me.forge.Patchsets.IterAll() {
|
|
for newpatch := range pset.Patches.IterAll() {
|
|
allPatchesPB.Append(newpatch)
|
|
}
|
|
}
|
|
return allPatchesPB
|
|
}
|
|
|
|
func sendPendingPatchsets(pb *forgepb.Patchsets, reqPB *httppb.HttpRequest) *forgepb.Patchsets {
|
|
allPatchsetsPB := new(forgepb.Patchsets)
|
|
for pset := range me.forge.Patchsets.IterAll() {
|
|
allPatchsetsPB.Append(pset)
|
|
}
|
|
return allPatchsetsPB
|
|
}
|
|
|
|
/*
|
|
func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
|
|
pb := forgepb.NewPatches()
|
|
err := pb.Unmarshal(reqPB.ServerData)
|
|
return pb, err
|
|
}
|
|
*/
|
|
|
|
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) {
|
|
pb := forgepb.NewPatchsets()
|
|
err := pb.Unmarshal(reqPB.ServerData)
|
|
return pb, err
|
|
}
|
|
|
|
func sendPatchesError(w http.ResponseWriter, r *forgepb.Patches, err error) error {
|
|
log.Info("send error back to user", err)
|
|
return nil
|
|
}
|