From b3b4cc8e571e29112b85b0fe6302864263e20b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 28 Apr 2025 12:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=90=8E=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=8E=B7=E5=8F=96=E9=AA=8C=E8=AF=81=E5=90=8E?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- validate.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/validate.go b/validate.go index 3c09f39..adb7e0d 100644 --- a/validate.go +++ b/validate.go @@ -155,6 +155,19 @@ func (h *handle) Marshal(marshalType string) ([]byte, error) { return serialize.Wrapper.Marshal(marshalType, h.Result()) } +// Map 直接获取map结果 +func (h *handle) Map(marshalType string) (map[string]any, error) { + if marshalType == "" { + marshalType = "json" // 默认按照json序列化 + } + var res map[string]any + err := h.Transform(marshalType, &res) + if nil != err { + return res, err + } + return res, nil +} + // Transform 数据转换 func (h *handle) Transform(targetType string, receiver any) error { if targetType == "" {