From e95ed61cfc4b09482e6ef8b5069aec7cb878a45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 19 Nov 2024 15:20:25 +0800 Subject: [PATCH] =?UTF-8?q?Map=E6=8F=90=E4=BE=9BSet=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/map.go b/map.go index ab8912c..6de1fd3 100644 --- a/map.go +++ b/map.go @@ -48,6 +48,25 @@ func (m *Map) Exist(key string) bool { return exist } +// Set 设置map的值, 字段如果已存在, 会覆盖 +// +// 参数说明: +// - field : 摇摆存的字段 +// - value : 字段对应的值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:16 2024/11/19 +func (m *Map) Set(field string, value any) error { + if nil == m { + return errors.New("Map is nil") + } + m.lock() + defer m.unlock() + (*m)[field] = value + return nil +} + // Get ... // // Author : go_developer@163.com<白茶清欢>