From 58073c7f5b43a6e85be2ee29ad6c766ceb12641c 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, 15 May 2023 18:08:56 +0800 Subject: [PATCH] update int --- define.go | 50 +++++++++++++++++++++++++++++ int.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) diff --git a/define.go b/define.go index 886bcbe..c8f8650 100644 --- a/define.go +++ b/define.go @@ -54,6 +54,16 @@ type Int8Result struct { Err error } +// Int8PtrResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:05 2023/5/15 +type Int8PtrResult struct { + Value *int8 + Err error +} + // Int16Result ... // // Author : go_developer@163.com<白茶清欢> @@ -64,6 +74,16 @@ type Int16Result struct { Err error } +// Int16PtrResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:05 2023/5/15 +type Int16PtrResult struct { + Value *int16 + Err error +} + // Int32Result ... // // Author : go_developer@163.com<白茶清欢> @@ -74,6 +94,16 @@ type Int32Result struct { Err error } +// Int32PtrResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:04 2023/5/15 +type Int32PtrResult struct { + Value *int32 + Err error +} + // Int64Result ... // // Author : go_developer@163.com<白茶清欢> @@ -84,6 +114,16 @@ type Int64Result struct { Err error } +// Int64PtrResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:04 2023/5/15 +type Int64PtrResult struct { + Value *int64 + Err error +} + // IntResult ... // // Author : go_developer@163.com<白茶清欢> @@ -214,6 +254,16 @@ type StringResult struct { Err error } +// StringPtrResult 字符串指针 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:02 2023/5/15 +type StringPtrResult struct { + Value *string + Err error +} + // Int8SliceResult ... // // Author : go_developer@163.com<白茶清欢> diff --git a/int.go b/int.go index f5ca495..4d6847e 100644 --- a/int.go +++ b/int.go @@ -37,6 +37,25 @@ func (i Int) ToInt8() Int8Result { return res } +// ToInt8Ptr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:08 2023/5/15 +func (i Int) ToInt8Ptr() Int8PtrResult { + res := i.ToInt8() + if nil != res.Err { + return Int8PtrResult{ + Value: nil, + Err: res.Err, + } + } + return Int8PtrResult{ + Value: &res.Value, + Err: nil, + } +} + // ToInt16 ... // // Author : go_developer@163.com<白茶清欢> @@ -55,6 +74,25 @@ func (i Int) ToInt16() Int16Result { return res } +// ToInt16Ptr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:07 2023/5/15 +func (i Int) ToInt16Ptr() Int16PtrResult { + res := i.ToInt16() + if nil != res.Err { + return Int16PtrResult{ + Value: nil, + Err: res.Err, + } + } + return Int16PtrResult{ + Value: &res.Value, + Err: nil, + } +} + // ToInt32 ... // // Author : go_developer@163.com<白茶清欢> @@ -73,6 +111,25 @@ func (i Int) ToInt32() Int32Result { return res } +// ToInt32Ptr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:07 2023/5/15 +func (i Int) ToInt32Ptr() Int32PtrResult { + res := i.ToInt32() + if nil != res.Err { + return Int32PtrResult{ + Value: nil, + Err: res.Err, + } + } + return Int32PtrResult{ + Value: &res.Value, + Err: nil, + } +} + // ToInt64 ... // // Author : go_developer@163.com<白茶清欢> @@ -91,6 +148,25 @@ func (i Int) ToInt64() Int64Result { return res } +// ToInt64Ptr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:05 2023/5/15 +func (i Int) ToInt64Ptr() Int64PtrResult { + res := i.ToInt64() + if nil != res.Err { + return Int64PtrResult{ + Value: nil, + Err: res.Err, + } + } + return Int64PtrResult{ + Value: &res.Value, + Err: nil, + } +} + // ToInt ... // // Author : go_developer@163.com<白茶清欢> @@ -145,3 +221,22 @@ func (i Int) ToString() StringResult { Err: nil, } } + +// ToStringPtr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:02 2023/5/15 +func (i Int) ToStringPtr() StringPtrResult { + result := i.ToString() + if nil != result.Err { + return StringPtrResult{ + Value: nil, + Err: result.Err, + } + } + return StringPtrResult{ + Value: &result.Value, + Err: nil, + } +}