convert http req directly to PB
This commit is contained in:
parent
f8b2ff5ace
commit
4e5a34b772
4
Makefile
4
Makefile
|
@ -3,14 +3,14 @@
|
||||||
VERSION = $(shell git describe --tags)
|
VERSION = $(shell git describe --tags)
|
||||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||||
|
|
||||||
all: build
|
all: build-verbose
|
||||||
./forged merge
|
./forged merge
|
||||||
|
|
||||||
build: goimports
|
build: goimports
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
verbose:
|
build-verbose:
|
||||||
GO111MODULE=off go build -v -x \
|
GO111MODULE=off go build -v -x \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
|
"go.wit.com/lib/protobuf/httppb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,6 +34,12 @@ func handlePatches(w http.ResponseWriter, r *http.Request, data []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
|
||||||
|
pb := forgepb.NewPatches()
|
||||||
|
err := pb.Unmarshal(reqPB.Body)
|
||||||
|
return pb, err
|
||||||
|
}
|
||||||
|
|
||||||
func sendPatchesError(w http.ResponseWriter, r *forgepb.Patches, err error) error {
|
func sendPatchesError(w http.ResponseWriter, r *forgepb.Patches, err error) error {
|
||||||
log.Info("send error back to user", err)
|
log.Info("send error back to user", err)
|
||||||
return nil
|
return nil
|
||||||
|
|
46
http.go
46
http.go
|
@ -2,13 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/lib/protobuf/httppb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,15 +49,14 @@ func whoSent(r *http.Request) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// something appears to be buggy. always get this first I guess
|
reqPB, err := httppb.ReqToPB(r)
|
||||||
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
if err != nil {
|
||||||
r.Body.Close()
|
log.Info("something crazy err", err)
|
||||||
log.Info("TRYING TO MARSHAL bytes:", len(msg), err)
|
}
|
||||||
|
|
||||||
who := whoSent(r)
|
who := whoSent(r)
|
||||||
|
|
||||||
var route string
|
route := reqPB.Route
|
||||||
route = cleanURL(r.URL.Path)
|
|
||||||
parts := strings.Split(route, "?")
|
parts := strings.Split(route, "?")
|
||||||
// log.Info("client sent url =", route, parts)
|
// log.Info("client sent url =", route, parts)
|
||||||
requrl := parts[0]
|
requrl := parts[0]
|
||||||
|
@ -78,7 +77,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Warn("forged REQUEST URL =", requrl, "from =", who)
|
log.Warn("forged REQUEST URL =", requrl, "from =", who)
|
||||||
|
|
||||||
if strings.HasPrefix(route, "/patches/") {
|
if strings.HasPrefix(route, "/patches/") {
|
||||||
handlePatches(w, r, msg)
|
pb, err := makePatchesPB(reqPB)
|
||||||
|
log.Info("err", err, "len", pb.Len())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/patchset" {
|
if route == "/patchset" {
|
||||||
if err := savePatchset(w, msg); err != nil {
|
if err := savePatchset(w, reqPB.Body); err != nil {
|
||||||
log.Warn("forged /patchset error", err)
|
log.Warn("forged /patchset error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/lookup" {
|
if route == "/lookup" {
|
||||||
log.Info("doing lookup len(msg) =", len(msg))
|
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
|
||||||
found, err := lookupRepos(msg)
|
found, err := lookupRepos(reqPB.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -117,12 +117,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(route, "/patches/") {
|
if strings.HasPrefix(route, "/patches/") {
|
||||||
handlePatches(w, r, msg)
|
handlePatches(w, r, reqPB.Body)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/patchset" {
|
if route == "/patchset" {
|
||||||
if err := savePatchset(w, msg); err != nil {
|
if err := savePatchset(w, reqPB.Body); err != nil {
|
||||||
log.Warn("forged /patchset error", err)
|
log.Warn("forged /patchset error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -134,8 +134,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/lookup" {
|
if route == "/lookup" {
|
||||||
log.Info("doing lookup len(msg) =", len(msg))
|
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
|
||||||
found, err := lookupRepos(msg)
|
found, err := lookupRepos(reqPB.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -151,12 +151,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(route, "/patches/") {
|
if strings.HasPrefix(route, "/patches/") {
|
||||||
handlePatches(w, r, msg)
|
handlePatches(w, r, reqPB.Body)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/patchset" {
|
if route == "/patchset" {
|
||||||
if err := savePatchset(w, msg); err != nil {
|
if err := savePatchset(w, reqPB.Body); err != nil {
|
||||||
log.Warn("forged /patchset error", err)
|
log.Warn("forged /patchset error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/lookup" {
|
if route == "/lookup" {
|
||||||
log.Info("doing lookup len(msg) =", len(msg))
|
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
|
||||||
found, err := lookupRepos(msg)
|
found, err := lookupRepos(reqPB.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/update" {
|
if route == "/update" {
|
||||||
log.Info("doing update len(msg) =", len(msg))
|
log.Info("doing update len(reqPB.Body) =", len(reqPB.Body))
|
||||||
found, err := updateRepos(msg)
|
found, err := updateRepos(reqPB.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -208,8 +208,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Info("going to w.Write(msg) with len", len(msg))
|
log.Info("going to w.Write(reqPB.Body) with len", len(reqPB.Body))
|
||||||
w.Write(msg)
|
w.Write(reqPB.Body)
|
||||||
*/
|
*/
|
||||||
age := shell.FormatDuration(time.Since(start))
|
age := shell.FormatDuration(time.Since(start))
|
||||||
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
|
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
|
||||||
|
|
Loading…
Reference in New Issue