init project

This commit is contained in:
admin committed 2025-12-05 17:23:29 +08:00
commit d63cc8d9f5
33 files changed
+1529

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
package server
import (
"context"
"fmt"
"strconv"
"git.xiaotuo.co/pkg/go-plugins/grpc/metax"
)
func GetBizId(ctx context.Context) (int64, error) {
bizId := getContextValue(ctx, "biz_id")
if bizId == "" {
return 0, fmt.Errorf("biz_id_is_empty")
}
return strconv.ParseInt(bizId, 10, 64)
}
func NewContext(ctx context.Context) (context.Context, error) {
ctx = metax.TransparentContext(ctx)
reqId, exists, err := metax.GetReqId(ctx)
if err != nil {
return ctx, fmt.Errorf("req_id_parse_fail")
}
if !exists {
return ctx, fmt.Errorf("req_id_not_found")
}
ctx = context.WithValue(ctx, "req_id", reqId)
bizId, exists, err := metax.GetBizId(ctx)
if err != nil {
return ctx, fmt.Errorf("biz_id_parse_fail")
}
if !exists {
return ctx, fmt.Errorf("biz_id_not_found")
}
ctx = context.WithValue(ctx, "biz_id", bizId)
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
}
}
return ""
}