init project

This commit is contained in:
admin committed 2026-11-11 17:49:38 +08:00
1 parent d63cc8d9f5
commit ee07869839
39 files changed
+1560 -622

No files matched your search

+11 -19
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strconv"
"git.xiaotuo.co/pkg/go-plugins/grpc/metax"
"google.golang.org/grpc/metadata"
)
func GetBizId(ctx context.Context) (int64, error) {
@@ -17,34 +17,26 @@ func GetBizId(ctx context.Context) (int64, error) {
}
func NewContext(ctx context.Context) (context.Context, error) {
ctx = metax.TransparentContext(ctx)
md, _ := metadata.FromIncomingContext(ctx)
ctx = metadata.NewOutgoingContext(ctx, md)
reqId, exists, err := metax.GetReqId(ctx)
if err != nil {
return ctx, fmt.Errorf("req_id_parse_fail")
}
if !exists {
reqIds := md.Get("req_id")
if len(reqIds) == 0 {
return ctx, fmt.Errorf("req_id_not_found")
}
ctx = context.WithValue(ctx, "req_id", reqId)
ctx = context.WithValue(ctx, "req_id", reqIds[0])
bizId, exists, err := metax.GetBizId(ctx)
if err != nil {
return ctx, fmt.Errorf("biz_id_parse_fail")
}
if !exists {
bizIds := md.Get("biz_id")
if len(bizIds) == 0 {
return ctx, fmt.Errorf("biz_id_not_found")
}
ctx = context.WithValue(ctx, "biz_id", bizId)
ctx = context.WithValue(ctx, "biz_id", bizIds[0])
return ctx, nil
}
func getContextValue(ctx context.Context, keyword string) string {
if ctx.Value(keyword) != nil {
if v, ok := ctx.Value(keyword).(string); ok {
return v
}
if value, ok := ctx.Value(keyword).(string); ok {
return value
}
return ""
}