zjh129 commented on code in PR #209:
URL: https://github.com/apache/skywalking-go/pull/209#discussion_r1804043835


##########
plugins/gozero/rest/server_middleware_intercepter.go:
##########
@@ -0,0 +1,70 @@
+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
+                       //s.Tag(tracing.TagHTTPResponse, "resp")
+               }
+
+               // collect response data
+               if config.CollectResponseData {
+                       //TODO: collect response data

Review Comment:
   The interceptor is currently unable to use packages other than enhanced 
objects, so we will remove the functionality for collecting request parameters 
and response data and will submit a PR once support is available in the future.



-- 
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]

Reply via email to