zjh129 commented on code in PR #209:
URL: https://github.com/apache/skywalking-go/pull/209#discussion_r1802640975
##########
plugins/gozero/rest/server_middleware_intercepter.go:
##########
@@ -0,0 +1,69 @@
+package rest
+
+import (
+ "fmt"
+ "github.com/apache/skywalking-go/plugins/core/operator"
+ "github.com/apache/skywalking-go/plugins/core/tracing"
+ "github.com/zeromicro/go-zero/rest"
+ "net/http"
+)
+
+type ServerMiddlewareInterceptor struct {
+}
+
+// skyWalking middleware
+var SkyWalkingMiddleware rest.Middleware = func(next http.HandlerFunc)
http.HandlerFunc {
+ return func(writer http.ResponseWriter, request *http.Request) {
+ s, err := tracing.CreateEntrySpan(fmt.Sprintf("%s:%s",
request.Method, request.URL.Path), func(headerKey string) (string, error) {
+ return request.Header.Get(headerKey), nil
+ }, tracing.WithLayer(tracing.SpanLayerHTTP),
+ tracing.WithTag(tracing.TagHTTPMethod, request.Method),
+ tracing.WithTag(tracing.TagURL,
request.Host+request.URL.Path),
+ tracing.WithComponent(5023))
+ if err != nil {
+ next(writer, request)
+ return
+ }
+
+ defer s.End()
+
+ // collect response data
+ if config.CollectRequestParameters {
+ switch request.Method {
+ case http.MethodGet:
+ if request.URL.RawQuery != "" {
+ s.Tag(tracing.TagHTTPParams,
request.URL.RawQuery)
+ }
+ case http.MethodPost, http.MethodPut, http.MethodPatch:
+ //TODO collect request body data
+ if request.Body != nil {
+ }
+ }
+ }
+
+ // collect response data
+ if config.CollectResponseData {
+ //TODO: collect response data
Review Comment:
I know that. When developing this feature, I needed to use the packages io,
bytes, encoding/json, regexp, and strings. At that time, I received the
following error when compiling the project:
skywalking_enhance_rest_server_middleware_intercepter.go:4:2: could not import
encoding/json. Currently, I am unable to resolve this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]