feature/upgrade_t #11
@ -1,18 +0,0 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-05-06 下午2:48
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArray_Unique(t *testing.T) {
|
||||
fmt.Println(ArrayType([]any{"1", 1, 1, "1", 2, 3}).Unique())
|
||||
fmt.Println(ArrayType([]int{1, 1, 2, 3}).Unique())
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
// Package wrapper ...
|
||||
// Package bigint ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-11-19 16:33
|
||||
package wrapper
|
||||
package bigint
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
302
define.go
302
define.go
@ -1,302 +0,0 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-05 14:44
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/op_type"
|
||||
)
|
||||
|
||||
// BaseTypeValueResult 基础类型结果
|
||||
type BaseTypeValueResult[BaseType op_type.BaseType] struct {
|
||||
Value BaseType `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int8Result ...
|
||||
type Int8Result struct {
|
||||
Value int8 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int8PtrResult ...
|
||||
type Int8PtrResult struct {
|
||||
Value *int8 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int16Result ...
|
||||
type Int16Result struct {
|
||||
Value int16 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int16PtrResult ...
|
||||
type Int16PtrResult struct {
|
||||
Value *int16 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int32Result ...
|
||||
type Int32Result struct {
|
||||
Value int32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int32PtrResult ...
|
||||
type Int32PtrResult struct {
|
||||
Value *int32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int64Result ...
|
||||
type Int64Result struct {
|
||||
Value int64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int64PtrResult ...
|
||||
type Int64PtrResult struct {
|
||||
Value *int64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// IntResult ...
|
||||
type IntResult struct {
|
||||
Value int `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// IntPtrResult ...
|
||||
type IntPtrResult struct {
|
||||
Value *int `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint8Result ...
|
||||
type Uint8Result struct {
|
||||
Value uint8 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint8PtrResult ...
|
||||
type Uint8PtrResult struct {
|
||||
Value *uint8 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint16Result ...
|
||||
type Uint16Result struct {
|
||||
Value uint16 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint16PtrResult ...
|
||||
type Uint16PtrResult struct {
|
||||
Value *uint16 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint32Result ...
|
||||
type Uint32Result struct {
|
||||
Value uint32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint32PtrResult ...
|
||||
type Uint32PtrResult struct {
|
||||
Value *uint32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint64Result ...
|
||||
type Uint64Result struct {
|
||||
Value uint64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint64PtrResult ...
|
||||
type Uint64PtrResult struct {
|
||||
Value *uint64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// UintResult ...
|
||||
type UintResult struct {
|
||||
Value uint `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// UintPtrResult ...
|
||||
type UintPtrResult struct {
|
||||
Value *uint `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Float32Result ...
|
||||
type Float32Result struct {
|
||||
Value float32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Float32PtrResult ...
|
||||
type Float32PtrResult struct {
|
||||
Value *float32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Float64Result ...
|
||||
type Float64Result struct {
|
||||
Value float64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Float64PtrResult ...
|
||||
type Float64PtrResult struct {
|
||||
Value *float64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Any ...
|
||||
type Any struct {
|
||||
Value any `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// BoolResult ...
|
||||
type BoolResult struct {
|
||||
Value bool `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// BoolPtrResult ...
|
||||
type BoolPtrResult struct {
|
||||
Value *bool `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// ObjectResult ...
|
||||
type ObjectResult struct {
|
||||
Value map[string]any `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// StringResult ...
|
||||
type StringResult struct {
|
||||
Value string `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// StringPtrResult 字符串指针
|
||||
type StringPtrResult struct {
|
||||
Value *string `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int8SliceResult ...
|
||||
type Int8SliceResult struct {
|
||||
Value []int8 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int16SliceResult ...
|
||||
type Int16SliceResult struct {
|
||||
Value []int16 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int32SliceResult ...
|
||||
type Int32SliceResult struct {
|
||||
Value []int32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Int64SliceResult ...
|
||||
type Int64SliceResult struct {
|
||||
Value []int64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// IntSliceResult ...
|
||||
type IntSliceResult struct {
|
||||
Value []int `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint8SliceResult ...
|
||||
type Uint8SliceResult struct {
|
||||
Value []uint8 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint16SliceResult ...
|
||||
type Uint16SliceResult struct {
|
||||
Value []uint16 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint32SliceResult ...
|
||||
type Uint32SliceResult struct {
|
||||
Value []uint32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Uint64SliceResult ...
|
||||
type Uint64SliceResult struct {
|
||||
Value []uint64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// UintSliceResult ...
|
||||
type UintSliceResult struct {
|
||||
Value []uint `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// BoolSliceResult ...
|
||||
type BoolSliceResult struct {
|
||||
Value []bool `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Float32SliceResult ...
|
||||
type Float32SliceResult struct {
|
||||
Value []float32 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// Float64SliceResult ...
|
||||
type Float64SliceResult struct {
|
||||
Value []float64 `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// DurationResult 时间转换结果
|
||||
type DurationResult struct {
|
||||
Value time.Duration `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// StringSliceResult ...
|
||||
type StringSliceResult struct {
|
||||
Value []string `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// MapResult 转map的结果
|
||||
type MapResult struct {
|
||||
Value any `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// AnySliceResult ...
|
||||
type AnySliceResult struct {
|
||||
Value []any `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
@ -52,7 +52,19 @@ type StructValueSliceResult[Value any] struct {
|
||||
}
|
||||
|
||||
// StringResult ...
|
||||
type StringResult struct {
|
||||
/*type StringResult struct {
|
||||
Value string `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}*/
|
||||
|
||||
// NumberResult 数字转换结果
|
||||
type NumberResult[ResultType op_type.Number] struct {
|
||||
Value ResultType `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
||||
// NumberPtrResult 数字指针转换结果
|
||||
type NumberPtrResult[ResultType op_type.Number] struct {
|
||||
Value *ResultType `json:"value"`
|
||||
Err error `json:"err"`
|
||||
}
|
||||
|
132
float.go
132
float.go
@ -1,132 +0,0 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-05 14:33
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// Float ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:33 2023/5/5
|
||||
type Float float64
|
||||
|
||||
// ToFloat32 ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:36 2023/5/5
|
||||
func (f Float) ToFloat32() Float32Result {
|
||||
res := Float32Result{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if f > math.MaxFloat32 || f < math.SmallestNonzeroFloat32 {
|
||||
res.Err = fmt.Errorf("float32 should between %v and %v", float32(math.SmallestNonzeroFloat32), float32(math.MaxFloat32))
|
||||
return res
|
||||
}
|
||||
res.Value = float32(f)
|
||||
return res
|
||||
}
|
||||
|
||||
// ToFloat32Ptr ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:10 2023/5/16
|
||||
func (f Float) ToFloat32Ptr() Float32PtrResult {
|
||||
res := f.ToFloat32()
|
||||
if nil != res.Err {
|
||||
return Float32PtrResult{
|
||||
Value: nil,
|
||||
Err: res.Err,
|
||||
}
|
||||
}
|
||||
return Float32PtrResult{
|
||||
Value: &res.Value,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ToFloat64 ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:36 2023/5/5
|
||||
func (f Float) ToFloat64() Float64Result {
|
||||
res := Float64Result{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if f > math.MaxFloat64 || f < math.SmallestNonzeroFloat64 {
|
||||
res.Err = fmt.Errorf("float32 should between %v and %v", float64(math.SmallestNonzeroFloat64), float64(math.MaxFloat64))
|
||||
return res
|
||||
}
|
||||
res.Value = float64(f)
|
||||
return res
|
||||
}
|
||||
|
||||
// ToFloat64Ptr ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:11 2023/5/16
|
||||
func (f Float) ToFloat64Ptr() Float64PtrResult {
|
||||
res := f.ToFloat64()
|
||||
if nil != res.Err {
|
||||
return Float64PtrResult{
|
||||
Value: nil,
|
||||
Err: res.Err,
|
||||
}
|
||||
}
|
||||
return Float64PtrResult{
|
||||
Value: &res.Value,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ToString ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:38 2023/5/5
|
||||
func (f Float) ToString() StringResult {
|
||||
floatVal := f.ToFloat64()
|
||||
if nil != floatVal.Err {
|
||||
return StringResult{
|
||||
Value: "",
|
||||
Err: floatVal.Err,
|
||||
}
|
||||
}
|
||||
return StringResult{
|
||||
Value: fmt.Sprintf("%v", floatVal.Value),
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ToStringPtr ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:56 2023/5/16
|
||||
func (f Float) ToStringPtr() StringPtrResult {
|
||||
res := f.ToString()
|
||||
if nil != res.Err {
|
||||
return StringPtrResult{
|
||||
Value: nil,
|
||||
Err: res.Err,
|
||||
}
|
||||
}
|
||||
return StringPtrResult{
|
||||
Value: &res.Value,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
255
int.go
255
int.go
@ -1,255 +0,0 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-05-05 13:56
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Int int类型
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 13:57 2023/5/5
|
||||
type Int int64
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// ToInt8 ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 13:57 2023/5/5
|
||||
func (i Int) ToInt8() Int8Result {
|
||||
res := Int8Result{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if math.MaxInt8 < int64(i) || math.MinInt8 > int64(i) {
|
||||
res.Err = fmt.Errorf("int8 value should between %v and %v ", int8(math.MinInt8), int8(math.MaxInt8))
|
||||
return res
|
||||
}
|
||||
res.Value = int8(i)
|
||||
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<白茶清欢>
|
||||
//
|
||||
// Date : 14:05 2023/5/5
|
||||
func (i Int) ToInt16() Int16Result {
|
||||
res := Int16Result{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if math.MaxInt16 < int64(i) || math.MinInt16 > int64(i) {
|
||||
res.Err = fmt.Errorf("int16 value should between %v and %v ", int16(math.MinInt16), int16(math.MaxInt16))
|
||||
return res
|
||||
}
|
||||
res.Value = int16(i)
|
||||
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<白茶清欢>
|
||||
//
|
||||
// Date : 14:05 2023/5/5
|
||||
func (i Int) ToInt32() Int32Result {
|
||||
res := Int32Result{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if math.MaxInt32 < int64(i) || math.MinInt32 > int64(i) {
|
||||
res.Err = fmt.Errorf("int32 value should between %v and %v ", int32(math.MinInt32), int32(math.MaxInt32))
|
||||
return res
|
||||
}
|
||||
res.Value = int32(i)
|
||||
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<白茶清欢>
|
||||
//
|
||||
// Date : 14:06 2023/5/5
|
||||
func (i Int) ToInt64() Int64Result {
|
||||
res := Int64Result{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if math.MaxInt64 < i || math.MinInt64 > i {
|
||||
res.Err = fmt.Errorf("int64 value should between %v and %v ", int64(math.MinInt64), int64(math.MaxInt64))
|
||||
return res
|
||||
}
|
||||
res.Value = int64(i)
|
||||
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<白茶清欢>
|
||||
//
|
||||
// Date : 14:07 2023/5/5
|
||||
func (i Int) ToInt() IntResult {
|
||||
res := IntResult{
|
||||
Value: 0,
|
||||
Err: nil,
|
||||
}
|
||||
if math.MaxInt < i || math.MinInt > i {
|
||||
res.Err = fmt.Errorf("int value should between %v and %v ", int(math.MinInt), int(math.MaxInt))
|
||||
}
|
||||
res.Value = int(i)
|
||||
return res
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
// ToString ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:07 2023/5/5
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
150
object.go
150
object.go
@ -1,150 +0,0 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-06-01 18:33
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// ObjectData 对象类型, 支持 nil / Map / Struct
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:36 2023/6/1
|
||||
func ObjectData(data any) *ObjectType {
|
||||
ot := &ObjectType{
|
||||
source: data,
|
||||
data: map[any]any{},
|
||||
byteData: []byte{},
|
||||
isValid: true,
|
||||
invalidErr: errors.New("data is invalid"),
|
||||
}
|
||||
if nil == ot {
|
||||
return ot
|
||||
}
|
||||
reflectType := reflect.TypeOf(data)
|
||||
switch reflectType.Kind() {
|
||||
case reflect.Map:
|
||||
fallthrough
|
||||
case reflect.Struct:
|
||||
ot.byteData, _ = json.Marshal(ot.source)
|
||||
default:
|
||||
// 数据类型不是 nil / map / struct 之一
|
||||
ot.isValid = false
|
||||
}
|
||||
return ot
|
||||
}
|
||||
|
||||
// ObjectType ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:38 2023/6/1
|
||||
type ObjectType struct {
|
||||
source any
|
||||
data map[any]any
|
||||
byteData []byte
|
||||
isValid bool
|
||||
invalidErr error
|
||||
}
|
||||
|
||||
// IsValid 是否有效对象数据
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:49 2023/6/1
|
||||
func (ot *ObjectType) IsValid() bool {
|
||||
return ot.isValid
|
||||
}
|
||||
|
||||
// IsNil 是否为nil
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:50 2023/6/1
|
||||
func (ot *ObjectType) IsNil() bool {
|
||||
if ot.source == nil {
|
||||
return true
|
||||
}
|
||||
return reflect.ValueOf(ot.source).IsNil()
|
||||
}
|
||||
|
||||
// ToString 转字符串
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:51 2023/6/1
|
||||
func (ot *ObjectType) ToString() StringResult {
|
||||
if ot.IsNil() {
|
||||
return StringResult{
|
||||
Value: "nil",
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
if !ot.IsValid() {
|
||||
// 非法对象数据
|
||||
return StringResult{
|
||||
Value: "",
|
||||
Err: errors.New("data is invalid"),
|
||||
}
|
||||
}
|
||||
return StringResult{
|
||||
Value: string(ot.byteData),
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ToMapStringAny ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:17 2023/6/2
|
||||
func (ot *ObjectType) ToMapStringAny() ObjectResult {
|
||||
res := ObjectResult{
|
||||
Value: map[string]any{},
|
||||
Err: nil,
|
||||
}
|
||||
if ot.IsNil() {
|
||||
return res
|
||||
}
|
||||
res.Err = serialize.JSON.UnmarshalWithNumber(ot.byteData, &res.Value)
|
||||
return res
|
||||
}
|
||||
|
||||
// ToStruct ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:41 2023/6/2
|
||||
func (ot *ObjectType) ToStruct(receiver any) error {
|
||||
if nil == receiver {
|
||||
return errors.New("receiver is nil")
|
||||
}
|
||||
if ot.IsNil() {
|
||||
return errors.New("data is nil")
|
||||
}
|
||||
return serialize.JSON.UnmarshalWithNumber(ot.byteData, receiver)
|
||||
}
|
||||
|
||||
// ToStructIgnoreErr ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:42 2023/6/2
|
||||
func (ot *ObjectType) ToStructIgnoreErr(receiver any) {
|
||||
if nil == receiver {
|
||||
return
|
||||
}
|
||||
if ot.IsNil() {
|
||||
return
|
||||
}
|
||||
_ = serialize.JSON.UnmarshalWithNumber(ot.byteData, receiver)
|
||||
}
|
86
op_number/number.go
Normal file
86
op_number/number.go
Normal file
@ -0,0 +1,86 @@
|
||||
// Package op_number ...
|
||||
//
|
||||
// Description : op_number ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2025-10-14 10:14
|
||||
package op_number
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/op_type"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper/convert"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper/define"
|
||||
)
|
||||
|
||||
// ToNumber ...
|
||||
func ToNumber[InputType op_type.BaseType, ResultType op_type.Number](in InputType) define.NumberResult[ResultType] {
|
||||
var (
|
||||
res ResultType
|
||||
err error
|
||||
)
|
||||
if err = convert.ConvertAssign(&res, in); err != nil {
|
||||
return define.NumberResult[ResultType]{
|
||||
Err: err,
|
||||
Value: res,
|
||||
}
|
||||
}
|
||||
return define.NumberResult[ResultType]{
|
||||
Err: nil,
|
||||
Value: res,
|
||||
}
|
||||
}
|
||||
|
||||
// ToNumberPtr 数字指针
|
||||
func ToNumberPtr[InputType op_type.BaseType, ResultType op_type.Number](in InputType) define.NumberPtrResult[ResultType] {
|
||||
var (
|
||||
res define.NumberResult[ResultType]
|
||||
)
|
||||
res = ToNumber[InputType, ResultType](in)
|
||||
if nil != res.Err {
|
||||
return define.NumberPtrResult[ResultType]{
|
||||
Err: res.Err,
|
||||
Value: nil,
|
||||
}
|
||||
}
|
||||
return define.NumberPtrResult[ResultType]{
|
||||
Err: nil,
|
||||
Value: &res.Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToString 转换为字符串
|
||||
func ToString[InputType op_type.Number](in InputType) define.BaseValueResult[string] {
|
||||
var (
|
||||
err error
|
||||
res string
|
||||
)
|
||||
if err = convert.ConvertAssign(&res, in); err != nil {
|
||||
return define.BaseValueResult[string]{
|
||||
Value: res,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return define.BaseValueResult[string]{
|
||||
Value: res,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ToStringPtr 字符串指针
|
||||
func ToStringPtr[InputType op_type.Number](in InputType) define.BaseValuePtrResult[string] {
|
||||
var (
|
||||
res define.BaseValueResult[string]
|
||||
)
|
||||
res = ToString[InputType](in)
|
||||
if nil != res.Err {
|
||||
return define.BaseValuePtrResult[string]{
|
||||
Err: res.Err,
|
||||
Value: nil,
|
||||
}
|
||||
}
|
||||
return define.BaseValuePtrResult[string]{
|
||||
Err: nil,
|
||||
Value: &res.Value,
|
||||
}
|
||||
}
|
@ -57,23 +57,23 @@ func SnakeCaseToCamel(str string) string {
|
||||
}
|
||||
|
||||
// Md5 计算Md5值
|
||||
func Md5(str string) define.StringResult {
|
||||
func Md5(str string) define.BaseValueResult[string] {
|
||||
h := md5.New()
|
||||
_, err := io.WriteString(h, str)
|
||||
if nil != err {
|
||||
return define.StringResult{
|
||||
return define.BaseValueResult[string]{
|
||||
Value: "",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return define.StringResult{
|
||||
return define.BaseValueResult[string]{
|
||||
Value: hex.EncodeToString(h.Sum(nil)),
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// RandomMd5 生成随机字符串MD%值
|
||||
func RandomMd5() define.StringResult {
|
||||
func RandomMd5() define.BaseValueResult[string] {
|
||||
str := Random(64, "")
|
||||
return Md5(str)
|
||||
}
|
||||
|
242
uint.go
242
uint.go
@ -1,242 +0,0 @@
|
||||
// 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,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user