more dumping and redoing patchset code
This commit is contained in:
parent
9025bf436a
commit
a94208a768
|
@ -14,58 +14,6 @@ import (
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func doSendPatchsets(w http.ResponseWriter) {
|
|
||||||
// log.HttpMode(w)
|
|
||||||
// defer log.HttpMode(nil)
|
|
||||||
|
|
||||||
dirname := filepath.Join(LIBDIR, "patchset/")
|
|
||||||
// Open the directory
|
|
||||||
entries, err := os.ReadDir(dirname)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error reading directory: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var psets *forgepb.Patchsets
|
|
||||||
psets = forgepb.NewPatchsets() // this sets the proper handshake protobuf UUID
|
|
||||||
|
|
||||||
// Iterate through the directory entries
|
|
||||||
for _, entry := range entries {
|
|
||||||
// Check if the entry is a file and matches the *.pb pattern
|
|
||||||
if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
|
|
||||||
bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(w, entry.Name(), err)
|
|
||||||
fmt.Println(entry.Name(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var p *forgepb.Patchset
|
|
||||||
p = new(forgepb.Patchset)
|
|
||||||
err = p.Unmarshal(bytes)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(w, entry.Name(), err)
|
|
||||||
fmt.Println(entry.Name(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
psets.Append(p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshal the protobuf to xfer over the socket
|
|
||||||
data, err := psets.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
log.Info("patchsets.Marshal() to wire failed", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
start := time.Now()
|
|
||||||
log.Info("going to w.Write(data) with len", len(data))
|
|
||||||
w.Write(data)
|
|
||||||
age := shell.FormatDuration(time.Since(start))
|
|
||||||
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPatchset(w http.ResponseWriter, pbname string) {
|
func getPatchset(w http.ResponseWriter, pbname string) {
|
||||||
if pbname == "" {
|
if pbname == "" {
|
||||||
fmt.Fprintf(w, "filename was empty")
|
fmt.Fprintf(w, "filename was empty")
|
||||||
|
|
14
http.go
14
http.go
|
@ -5,7 +5,9 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,7 +86,17 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/GetPatchsets" {
|
if route == "/GetPatchsets" {
|
||||||
doSendPatchsets(w)
|
data, err := me.forge.Patchsets.Marshal()
|
||||||
|
if err != nil {
|
||||||
|
log.Info("patchsets.Marshal() to wire failed", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
log.Info("going to w.Write(data) with len", len(data))
|
||||||
|
w.Write(data)
|
||||||
|
age := shell.FormatDuration(time.Since(start))
|
||||||
|
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue