From 0d9fa31401fa5a39915464d2f392554c77317dcb 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, 24 Nov 2021 22:24:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=BB=E5=8F=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=B9=B6=E8=A7=A3=E6=9E=90=E6=88=90=E5=88=B6=E5=AE=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/apollo/extend.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 middleware/apollo/extend.go diff --git a/middleware/apollo/extend.go b/middleware/apollo/extend.go new file mode 100644 index 0000000..c4bc3fb --- /dev/null +++ b/middleware/apollo/extend.go @@ -0,0 +1,28 @@ +// Package apollo... +// +// Description : 扩展第三方库的一些函数 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-11-24 10:16 下午 +package apollo + +import ( + "git.zhangdeman.cn/zhangdeman/gopkg/util" + "github.com/pkg/errors" +) + +// GetValueWithReceiver 读取数据,并解析到指定的数据结构中 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 10:18 下午 2021/11/24 +func GetValueWithReceiver(key string, receiver interface{}) error { + var ( + result string + ) + if result = Client.GetStringValue(key, ""); len(result) == 0 { + return errors.New("key is not found : " + key) + } + return util.JSONUnmarshalWithNumber([]byte(result), receiver) +}