From fcaa7ee1c243bad4cf4c9113b750baf19cc24bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 6 Nov 2024 19:50:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0map=20clone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/map.go b/map.go index 6d23965..9a16202 100644 --- a/map.go +++ b/map.go @@ -44,3 +44,34 @@ func (m *Map) Exist(key string) bool { _, exist := v[key] return exist } + +// Value 获取数据值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 19:39 2024/11/6 +func (m *Map) Value() Map { + if nil == m { + return map[string]any{} + } + return *m +} + +// Clone 克隆数据 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 19:40 2024/11/6 +func (m *Map) Clone() Map { + newData := map[string]any{} + if nil == m { + return newData + } + m.rlock() + defer m.unlock() + mapValue := m.Value() + for k, v := range mapValue { + newData[k] = v + } + return newData +}