From 2493ce45d83353dc681f15924977190ebf79edaf Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Wed, 17 Jan 2024 17:41:36 +0800 Subject: [PATCH] fix: fix the func --- internal/api/msg.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index 23a38fcaf..1aae10074 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -36,6 +36,7 @@ import ( pbmsg "github.com/openimsdk/open-im-server/v3/tools/data-conversion/openim/proto/msg" "net/http" "reflect" + "strings" "github.com/openimsdk/open-im-server/v3/pkg/apistruct" "github.com/openimsdk/open-im-server/v3/pkg/rpcclient" @@ -537,8 +538,19 @@ func convertStructToMap(input interface{}) (map[string]interface{}, error) { field := inputType.Field(i) fieldValue := inputValue.Field(i) + // 获取mapstructure标签的值作为map的键 + mapKey := field.Tag.Get("mapstructure") + fmt.Println(mapKey) + // 如果没有mapstructure标签,则使用字段名作为键 + if mapKey == "" { + mapKey = field.Name + } + + // 转换为小写形式,以匹配JSON的命名约定 + mapKey = strings.ToLower(mapKey) + // 将字段名作为 map 的键,字段值作为 map 的值 - result[field.Name] = fieldValue.Interface() + result[mapKey] = fieldValue.Interface() } return result, nil