diff --git a/.dockerignore b/.dockerignore index 328cc438..69683a85 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ -deployments .git +docs +node_modules +deployments .github *.pb.go \ No newline at end of file diff --git a/go.mod b/go.mod index 5c853fc0..ea8581d0 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 - github.com/gripmock/stuber v0.0.0-20240411211057-abb2f3d06dcb + github.com/gripmock/stuber v0.0.0-20240412102748-e33bea496d15 github.com/jhump/protoreflect v1.16.0 github.com/joho/godotenv v1.5.1 github.com/kelseyhightower/envconfig v1.4.0 diff --git a/go.sum b/go.sum index 48b8a7c5..1ae9e7e9 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,8 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gripmock/deeply v1.0.7 h1:qYLBu8/x9xq0kvHV5UG/SIP9M23T11jkcUgzhn1xGIU= github.com/gripmock/deeply v1.0.7/go.mod h1:xKJ9we/cU0CnCoYa+En2MirViTzvgsNp5B0hya1DhKk= -github.com/gripmock/stuber v0.0.0-20240411211057-abb2f3d06dcb h1:2ZQE4VegnSudNAn0YzdF6AH4GJSv6kSdKqMg/R6l5NM= -github.com/gripmock/stuber v0.0.0-20240411211057-abb2f3d06dcb/go.mod h1:CrbeiDxvJX1xsrUwcEVhCmNz4CQPq0z7RfXLIHOgsn0= +github.com/gripmock/stuber v0.0.0-20240412102748-e33bea496d15 h1:7VlvlnhZpKiEaE9EOu/QPCxoAkvQ8Plje+pLlMuIECw= +github.com/gripmock/stuber v0.0.0-20240412102748-e33bea496d15/go.mod h1:CrbeiDxvJX1xsrUwcEVhCmNz4CQPq0z7RfXLIHOgsn0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= github.com/jhump/protoreflect v1.16.0 h1:54fZg+49widqXYQ0b+usAFHbMkBGR4PpXrsHc8+TBDg= diff --git a/internal/pkg/muxmiddleware/logger.go b/internal/pkg/muxmiddleware/logger.go index f0bfcb7a..526b5b33 100644 --- a/internal/pkg/muxmiddleware/logger.go +++ b/internal/pkg/muxmiddleware/logger.go @@ -1,6 +1,8 @@ package muxmiddleware import ( + "bytes" + "io" "net/http" "time" @@ -14,6 +16,10 @@ func RequestLogger(next http.Handler) http.Handler { ip, err := getIP(r) now := time.Now() + bodyBytes, _ := io.ReadAll(r.Body) + r.Body.Close() // must close + r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + next.ServeHTTP(ww, r) logger. @@ -22,6 +28,7 @@ func RequestLogger(next http.Handler) http.Handler { IPAddr("ip", ip). Str("method", r.Method). Str("url", r.URL.RequestURI()). + RawJSON("input", bodyBytes). Dur("elapsed", time.Since(now)). Str("ua", r.UserAgent()). Int("bytes", ww.bytes). diff --git a/protoc-gen-gripmock/server.tmpl b/protoc-gen-gripmock/server.tmpl index fecbd9c2..b709df8f 100644 --- a/protoc-gen-gripmock/server.tmpl +++ b/protoc-gen-gripmock/server.tmpl @@ -186,17 +186,6 @@ func (s *{{.ServiceName}}) {{.Name}}(srv {{.SvcPackage}}{{.ServiceName}}_{{.Name {{ end }} {{ define "find_stub" }} -type payload struct { - Service string `json:"service"` - Method string `json:"method"` - Data interface{} `json:"data"` -} - -type response struct { - Data interface{} `json:"data"` - Error string `json:"error"` -} - func findStub(ctx context.Context, service, method string, md metadata.MD, in, out protoreflect.ProtoMessage) error { api, err := sdk.NewClientWithResponses(fmt.Sprintf("http://localhost%s/api", HTTP_PORT), sdk.WithHTTPClient(http.DefaultClient),