builds. puts http headers in protobuf
This commit is contained in:
parent
1442d4f6c5
commit
b2af891b20
11
Makefile
11
Makefile
|
@ -3,9 +3,9 @@
|
|||
VERSION = $(shell git describe --tags)
|
||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||
|
||||
all: install
|
||||
forged merge
|
||||
forged
|
||||
all: build
|
||||
./forged merge
|
||||
./forged
|
||||
|
||||
build: goimports
|
||||
GO111MODULE=off go build \
|
||||
|
@ -40,6 +40,11 @@ run: build
|
|||
systemctl stop forged.service
|
||||
./forged --daemon
|
||||
# setcap 'cap_net_bind_service=+ep' forged # allow the binary to open ports below 1024
|
||||
#
|
||||
run-clean: build
|
||||
-rm /var/lib/forged/all-patches.pb
|
||||
./forged --daemon
|
||||
# setcap 'cap_net_bind_service=+ep' forged # allow the binary to open ports below 1024
|
||||
|
||||
prod: build
|
||||
make stop
|
||||
|
|
|
@ -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
|
||||
}
|
5
http.go
5
http.go
|
@ -139,6 +139,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(route, "/patches/") {
|
||||
handlePatches(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/goReference.svg" {
|
||||
w.Header().Set("Content-Type", "image/svg+xml")
|
||||
writeFile(w, "goReference.svg")
|
||||
|
|
Loading…
Reference in New Issue