zjh129 commented on code in PR #209:
URL: https://github.com/apache/skywalking-go/pull/209#discussion_r1803978562
##########
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:
I know this place. I encountered an issue where I couldn't use extra
packages while developing the interceptor functionality; otherwise, I get the
error: `skywalking_enhance_rest_server_middleware_intercepter.go:4:2: could not
import encoding/json`. I am currently waiting for a solution.
--
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]