回调
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 30s
CI / admin (push) Successful in 22s
CI / bff (push) Successful in 39s
CI / chore (push) Successful in 20s
CI / equipment (push) Successful in 19s
CI / express (push) Successful in 17s
CI / product (push) Successful in 16s
CI / record (push) Successful in 17s
CI / sale (push) Successful in 16s
CI / task (push) Successful in 16s
CI / user (push) Successful in 17s
CI / wecom (push) Successful in 18s

This commit is contained in:
2026-09-05 13:41:13 +08:00
parent be18a48148
commit 462d142a4c
9 changed files with 254 additions and 83 deletions
+6 -20
View File
@@ -2,7 +2,6 @@ package utils
import (
"context"
"net/http"
"net/url"
"strconv"
@@ -10,12 +9,6 @@ import (
"google.golang.org/grpc/metadata"
)
const (
CtxCallbackRawBody string = "callback_raw_body"
CtxCallbackHeaders string = "callback_headers"
CtxCallbackErr string = "callback_read_err"
)
type UserInfo struct {
ID int64
Name string
@@ -38,11 +31,6 @@ type UserInfo struct {
Valid bool
}
type HeaderAndBody struct {
Header http.Header
Body []byte
}
func firstMD(md metadata.MD, keys ...string) string {
for _, key := range keys {
vals := md.Get(key)
@@ -122,13 +110,11 @@ func GetUserFromCtx(ctx context.Context) UserInfo {
return userInfo
}
// GetHeaderAndBody 只从ctx拿数据,不写http响应,Err交给handler处理
func GetHeaderAndBody(ctx context.Context) HeaderAndBody {
rawBody, _ := ctx.Value(CtxCallbackRawBody).([]byte)
headers, _ := ctx.Value(CtxCallbackHeaders).(http.Header)
return HeaderAndBody{
Header: headers,
Body: rawBody,
// GetBody 只从ctx拿数据,不写http响应,Err交给handler处理
func GetBody(ctx context.Context) string {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return StringEmpty
}
return firstMD(md, "x-raw-body")
}