2023-05-05 14:08:34 +08:00
|
|
|
// Package wrapper ...
|
|
|
|
//
|
|
|
|
// Description : wrapper ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2023-05-05 13:56
|
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
2023-09-04 20:35:42 +08:00
|
|
|
"time"
|
2023-05-05 14:08:34 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Int int类型
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 13:57 2023/5/5
|
|
|
|
type Int int64
|
|
|
|
|
2023-09-04 20:35:42 +08:00
|
|
|
// ToDuration ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 20:33 2023/9/4
|
|
|
|
func (i Int) ToDuration(timeUnit time.Duration) DurationResult {
|
|
|
|
return DurationResult{
|
|
|
|
Value: time.Duration(i.ToInt64().Value) * timeUnit,
|
|
|
|
Err: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:08:34 +08:00
|
|
|
// ToInt8 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 13:57 2023/5/5
|
2023-05-08 16:59:46 +08:00
|
|
|
func (i Int) ToInt8() Int8Result {
|
|
|
|
res := Int8Result{
|
|
|
|
Value: 0,
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 14:08:34 +08:00
|
|
|
if math.MaxInt8 < int64(i) || math.MinInt8 > int64(i) {
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Err = fmt.Errorf("int8 value should between %v and %v ", int8(math.MinInt8), int8(math.MaxInt8))
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Value = int8(i)
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 18:08:56 +08:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:08:34 +08:00
|
|
|
// ToInt16 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 14:05 2023/5/5
|
2023-05-08 16:59:46 +08:00
|
|
|
func (i Int) ToInt16() Int16Result {
|
|
|
|
res := Int16Result{
|
|
|
|
Value: 0,
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 14:08:34 +08:00
|
|
|
if math.MaxInt16 < int64(i) || math.MinInt16 > int64(i) {
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Err = fmt.Errorf("int16 value should between %v and %v ", int16(math.MinInt16), int16(math.MaxInt16))
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Value = int16(i)
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 18:08:56 +08:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:08:34 +08:00
|
|
|
// ToInt32 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 14:05 2023/5/5
|
2023-05-08 16:59:46 +08:00
|
|
|
func (i Int) ToInt32() Int32Result {
|
|
|
|
res := Int32Result{
|
|
|
|
Value: 0,
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 14:08:34 +08:00
|
|
|
if math.MaxInt32 < int64(i) || math.MinInt32 > int64(i) {
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Err = fmt.Errorf("int32 value should between %v and %v ", int32(math.MinInt32), int32(math.MaxInt32))
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Value = int32(i)
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 18:08:56 +08:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:08:34 +08:00
|
|
|
// ToInt64 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 14:06 2023/5/5
|
2023-05-08 16:59:46 +08:00
|
|
|
func (i Int) ToInt64() Int64Result {
|
|
|
|
res := Int64Result{
|
|
|
|
Value: 0,
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 14:08:34 +08:00
|
|
|
if math.MaxInt64 < i || math.MinInt64 > i {
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Err = fmt.Errorf("int64 value should between %v and %v ", int64(math.MinInt64), int64(math.MaxInt64))
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Value = int64(i)
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 18:08:56 +08:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:08:34 +08:00
|
|
|
// ToInt ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 14:07 2023/5/5
|
2023-05-08 16:59:46 +08:00
|
|
|
func (i Int) ToInt() IntResult {
|
|
|
|
res := IntResult{
|
|
|
|
Value: 0,
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 14:08:34 +08:00
|
|
|
if math.MaxInt < i || math.MinInt > i {
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Err = fmt.Errorf("int value should between %v and %v ", int(math.MinInt), int(math.MaxInt))
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
2023-05-08 16:59:46 +08:00
|
|
|
res.Value = int(i)
|
|
|
|
return res
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 17:53:24 +08:00
|
|
|
// ToIntPtr ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 17:52 2023/5/15
|
|
|
|
func (i Int) ToIntPtr() IntPtrResult {
|
|
|
|
intRes := i.ToInt()
|
|
|
|
if nil != intRes.Err {
|
|
|
|
return IntPtrResult{
|
|
|
|
Value: nil,
|
|
|
|
Err: intRes.Err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IntPtrResult{
|
|
|
|
Value: &intRes.Value,
|
|
|
|
Err: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:08:34 +08:00
|
|
|
// ToString ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 14:07 2023/5/5
|
2023-05-08 16:59:46 +08:00
|
|
|
func (i Int) ToString() StringResult {
|
|
|
|
result := i.ToInt64()
|
|
|
|
if nil != result.Err {
|
|
|
|
return StringResult{
|
|
|
|
Value: "",
|
|
|
|
Err: result.Err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return StringResult{
|
|
|
|
Value: fmt.Sprintf("%v", result.Value),
|
|
|
|
Err: nil,
|
2023-05-05 16:07:42 +08:00
|
|
|
}
|
2023-05-05 14:08:34 +08:00
|
|
|
}
|
2023-05-15 18:08:56 +08:00
|
|
|
|
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|