From e8ff7ffe8e8c25195c64950b61c6c5754bbcd3ba Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Sun, 19 Feb 2017 00:25:42 +0000 Subject: Add grpc signer --- cmd/cashierd/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cmd/cashierd/main.go') diff --git a/cmd/cashierd/main.go b/cmd/cashierd/main.go index 8164cf7..d355604 100644 --- a/cmd/cashierd/main.go +++ b/cmd/cashierd/main.go @@ -17,6 +17,7 @@ import ( "strings" "github.com/pkg/errors" + "github.com/soheilhy/cmux" "go4.org/wkfs" "golang.org/x/crypto/acme/autocert" @@ -153,8 +154,7 @@ func signHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er token := &oauth2.Token{ AccessToken: t, } - ok := authprovider.Valid(token) - if !ok { + if !authprovider.Valid(token) { return http.StatusUnauthorized, errors.New(http.StatusText(http.StatusUnauthorized)) } @@ -174,7 +174,7 @@ func signHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er } if err := json.NewEncoder(w).Encode(&lib.SignResponse{ Status: "ok", - Response: lib.GetPublicKey(cert), + Response: string(lib.GetPublicKey(cert)), }); err != nil { return http.StatusInternalServerError, errors.Wrap(err, "error encoding response") } @@ -425,5 +425,11 @@ func main() { s := &http.Server{ Handler: h, } - log.Fatal(s.Serve(l)) + + cm := cmux.New(l) + httpl := cm.Match(cmux.HTTP1Fast()) + grpcl := cm.Match(cmux.HTTP2HeaderField("content-type", "application/grpc")) + go s.Serve(httpl) + go newGrpcServer(grpcl) + log.Fatal(cm.Serve()) } -- cgit v1.2.3