243 lines
4.2 KiB
Go
243 lines
4.2 KiB
Go
// Package wrapper ...
|
|
//
|
|
// Description : wrapper ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2023-05-05 14:20
|
|
package wrapper
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
)
|
|
|
|
// Uint ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:20 2023/5/5
|
|
type Uint uint64
|
|
|
|
// ToUint8 ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:21 2023/5/5
|
|
func (ui Uint) ToUint8() Uint8Result {
|
|
res := Uint8Result{
|
|
Value: 0,
|
|
Err: nil,
|
|
}
|
|
if ui > math.MaxUint8 || ui < 0 {
|
|
res.Err = fmt.Errorf("uint8 should between 0 and %v", uint8(math.MaxUint8))
|
|
return res
|
|
}
|
|
res.Value = uint8(ui)
|
|
return res
|
|
}
|
|
|
|
// ToUint8Ptr ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 10:54 2023/5/16
|
|
func (ui Uint) ToUint8Ptr() Uint8PtrResult {
|
|
res := ui.ToUint8()
|
|
if nil != res.Err {
|
|
return Uint8PtrResult{
|
|
Value: nil,
|
|
Err: res.Err,
|
|
}
|
|
}
|
|
return Uint8PtrResult{
|
|
Value: &res.Value,
|
|
Err: nil,
|
|
}
|
|
}
|
|
|
|
// ToUint16 ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:25 2023/5/5
|
|
func (ui Uint) ToUint16() Uint16Result {
|
|
res := Uint16Result{
|
|
Value: 0,
|
|
Err: nil,
|
|
}
|
|
if ui > math.MaxUint16 || ui < 0 {
|
|
res.Err = fmt.Errorf("uint16 should between 0 and %v", uint16(math.MaxUint16))
|
|
return res
|
|
}
|
|
res.Value = uint16(ui)
|
|
return res
|
|
}
|
|
|
|
// ToUint16Ptr ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 10:55 2023/5/16
|
|
func (ui Uint) ToUint16Ptr() Uint16PtrResult {
|
|
res := ui.ToUint16()
|
|
if nil != res.Err {
|
|
return Uint16PtrResult{
|
|
Value: nil,
|
|
Err: res.Err,
|
|
}
|
|
}
|
|
return Uint16PtrResult{
|
|
Value: &res.Value,
|
|
Err: nil,
|
|
}
|
|
}
|
|
|
|
// ToUint32 ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:25 2023/5/5
|
|
func (ui Uint) ToUint32() Uint32Result {
|
|
res := Uint32Result{
|
|
Value: 0,
|
|
Err: nil,
|
|
}
|
|
if ui > math.MaxUint32 || ui < 0 {
|
|
res.Err = fmt.Errorf("uint32 should between 0 and %v", uint32(math.MaxUint32))
|
|
return res
|
|
}
|
|
res.Value = uint32(ui)
|
|
return res
|
|
}
|
|
|
|
// ToUint32Ptr ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 10:55 2023/5/16
|
|
func (ui Uint) ToUint32Ptr() Uint32PtrResult {
|
|
res := ui.ToUint32()
|
|
if nil != res.Err {
|
|
return Uint32PtrResult{
|
|
Value: nil,
|
|
Err: res.Err,
|
|
}
|
|
}
|
|
return Uint32PtrResult{
|
|
Value: &res.Value,
|
|
Err: nil,
|
|
}
|
|
}
|
|
|
|
// ToUint64 ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:30 2023/5/5
|
|
func (ui Uint) ToUint64() Uint64Result {
|
|
res := Uint64Result{
|
|
Value: 0,
|
|
Err: nil,
|
|
}
|
|
if ui > math.MaxUint64 || ui < 0 {
|
|
res.Err = fmt.Errorf("uint64 should between 0 and %v", uint64(math.MaxUint64))
|
|
}
|
|
res.Value = uint64(ui)
|
|
return res
|
|
}
|
|
|
|
// ToUint64Ptr ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 10:57 2023/5/16
|
|
func (ui Uint) ToUint64Ptr() Uint64PtrResult {
|
|
res := ui.ToUint64()
|
|
if nil != res.Err {
|
|
return Uint64PtrResult{
|
|
Value: nil,
|
|
Err: res.Err,
|
|
}
|
|
}
|
|
return Uint64PtrResult{
|
|
Value: &res.Value,
|
|
Err: nil,
|
|
}
|
|
}
|
|
|
|
// ToUint ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:31 2023/5/5
|
|
func (ui Uint) ToUint() UintResult {
|
|
res := UintResult{
|
|
Value: 0,
|
|
Err: nil,
|
|
}
|
|
if ui > math.MaxUint || ui < 0 {
|
|
res.Err = fmt.Errorf("uint should between 0 and %v", uint(math.MaxUint))
|
|
return res
|
|
}
|
|
res.Value = uint(ui)
|
|
return res
|
|
}
|
|
|
|
// ToUintPtr ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 10:57 2023/5/16
|
|
func (ui Uint) ToUintPtr() UintPtrResult {
|
|
res := ui.ToUint()
|
|
if nil != res.Err {
|
|
return UintPtrResult{
|
|
Value: nil,
|
|
Err: res.Err,
|
|
}
|
|
}
|
|
return UintPtrResult{
|
|
Value: &res.Value,
|
|
Err: nil,
|
|
}
|
|
}
|
|
|
|
// ToString ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 14:32 2023/5/5
|
|
func (ui Uint) ToString() StringResult {
|
|
uint64Val := ui.ToUint64()
|
|
if nil != uint64Val.Err {
|
|
return StringResult{
|
|
Value: "",
|
|
Err: uint64Val.Err,
|
|
}
|
|
}
|
|
return StringResult{
|
|
Value: fmt.Sprintf("%v", uint64Val),
|
|
Err: nil,
|
|
}
|
|
}
|
|
|
|
// ToStringPtr ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 10:59 2023/5/16
|
|
func (ui Uint) ToStringPtr() StringPtrResult {
|
|
res := ui.ToString()
|
|
if nil != res.Err {
|
|
return StringPtrResult{
|
|
Value: nil,
|
|
Err: res.Err,
|
|
}
|
|
}
|
|
return StringPtrResult{
|
|
Value: &res.Value,
|
|
Err: nil,
|
|
}
|
|
}
|