dcsunny 4 роки тому
батько
коміт
bbf91a9980
2 змінених файлів з 7 додано та 4 видалено
  1. 6 1
      http/context/context.go
  2. 1 3
      http/handle.go

+ 6 - 1
http/context/context.go

@@ -21,6 +21,11 @@ func AppendToContext(ctx context.Context, key string, value interface{}) context
 		_value = fmt.Sprint(value)
 		break
 	}
-	ctx = metadata.AppendToOutgoingContext(ctx, key, _value)
+	md, _, ex := metadata.FromOutgoingContextRaw(ctx)
+	if !ex {
+		md = metadata.New(map[string]string{})
+	}
+	md.Set(key, _value)
+	ctx = metadata.NewOutgoingContext(ctx, md)
 	return ctx
 }

+ 1 - 3
http/handle.go

@@ -4,7 +4,6 @@ import (
 	"bytes"
 	"context"
 	json2 "encoding/json"
-	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strings"
@@ -218,8 +217,7 @@ func contentSubtype(contentType string) string {
 func SetBody(ctx context.Context, r *http.Request) context.Context {
 	b, _ := ioutil.ReadAll(r.Body)
 	if len(b) > 0 {
-		fmt.Println(string(b))
-		ctx = context2.AppendToContext(ctx, "body", b)
+		ctx = context2.AppendToContext(ctx, "body", r.Body)
 	}
 	return ctx
 }