数据操作升级为基于泛型实现 #10

Merged
zhangdeman merged 8 commits from feature/support_genericity into master 2025-10-13 17:10:54 +08:00
2 changed files with 108 additions and 531 deletions
Showing only changes of commit 460672bcd0 - Show all commits

384
define.go
View File

@@ -9,474 +9,294 @@ package wrapper
import ( import (
"time" "time"
"git.zhangdeman.cn/zhangdeman/op_type"
) )
// BaseTypeValueResult 基础类型结果
type BaseTypeValueResult[BaseType op_type.BaseType] struct {
Value BaseType `json:"value"`
Err error `json:"err"`
}
// Int8Result ... // Int8Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:25 2023/5/8
type Int8Result struct { type Int8Result struct {
Value int8 Value int8 `json:"value"`
Err error Err error `json:"err"`
} }
// Int8PtrResult ... // Int8PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:05 2023/5/15
type Int8PtrResult struct { type Int8PtrResult struct {
Value *int8 Value *int8 `json:"value"`
Err error Err error `json:"err"`
} }
// Int16Result ... // Int16Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:26 2023/5/8
type Int16Result struct { type Int16Result struct {
Value int16 Value int16 `json:"value"`
Err error Err error `json:"err"`
} }
// Int16PtrResult ... // Int16PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:05 2023/5/15
type Int16PtrResult struct { type Int16PtrResult struct {
Value *int16 Value *int16 `json:"value"`
Err error Err error `json:"err"`
} }
// Int32Result ... // Int32Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:26 2023/5/8
type Int32Result struct { type Int32Result struct {
Value int32 Value int32 `json:"value"`
Err error Err error `json:"err"`
} }
// Int32PtrResult ... // Int32PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:04 2023/5/15
type Int32PtrResult struct { type Int32PtrResult struct {
Value *int32 Value *int32 `json:"value"`
Err error Err error `json:"err"`
} }
// Int64Result ... // Int64Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:26 2023/5/8
type Int64Result struct { type Int64Result struct {
Value int64 Value int64 `json:"value"`
Err error Err error `json:"err"`
} }
// Int64PtrResult ... // Int64PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:04 2023/5/15
type Int64PtrResult struct { type Int64PtrResult struct {
Value *int64 Value *int64 `json:"value"`
Err error Err error `json:"err"`
} }
// IntResult ... // IntResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:26 2023/5/8
type IntResult struct { type IntResult struct {
Value int Value int `json:"value"`
Err error Err error `json:"err"`
} }
// IntPtrResult ... // IntPtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:51 2023/5/15
type IntPtrResult struct { type IntPtrResult struct {
Value *int Value *int `json:"value"`
Err error Err error `json:"err"`
} }
// Uint8Result ... // Uint8Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:28 2023/5/8
type Uint8Result struct { type Uint8Result struct {
Value uint8 Value uint8 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint8PtrResult ... // Uint8PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:49 2023/5/16
type Uint8PtrResult struct { type Uint8PtrResult struct {
Value *uint8 Value *uint8 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint16Result ... // Uint16Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:28 2023/5/8
type Uint16Result struct { type Uint16Result struct {
Value uint16 Value uint16 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint16PtrResult ... // Uint16PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:49 2023/5/16
type Uint16PtrResult struct { type Uint16PtrResult struct {
Value *uint16 Value *uint16 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint32Result ... // Uint32Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:28 2023/5/8
type Uint32Result struct { type Uint32Result struct {
Value uint32 Value uint32 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint32PtrResult ... // Uint32PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:49 2023/5/16
type Uint32PtrResult struct { type Uint32PtrResult struct {
Value *uint32 Value *uint32 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint64Result ... // Uint64Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:28 2023/5/8
type Uint64Result struct { type Uint64Result struct {
Value uint64 Value uint64 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint64PtrResult ... // Uint64PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:50 2023/5/16
type Uint64PtrResult struct { type Uint64PtrResult struct {
Value *uint64 Value *uint64 `json:"value"`
Err error Err error `json:"err"`
} }
// UintResult ... // UintResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:29 2023/5/8
type UintResult struct { type UintResult struct {
Value uint Value uint `json:"value"`
Err error Err error `json:"err"`
} }
// UintPtrResult ... // UintPtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:51 2023/5/16
type UintPtrResult struct { type UintPtrResult struct {
Value *uint Value *uint `json:"value"`
Err error Err error `json:"err"`
} }
// Float32Result ... // Float32Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:31 2023/5/8
type Float32Result struct { type Float32Result struct {
Value float32 Value float32 `json:"value"`
Err error Err error `json:"err"`
} }
// Float32PtrResult ... // Float32PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:10 2023/5/16
type Float32PtrResult struct { type Float32PtrResult struct {
Value *float32 Value *float32 `json:"value"`
Err error Err error `json:"err"`
} }
// Float64Result ... // Float64Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:32 2023/5/8
type Float64Result struct { type Float64Result struct {
Value float64 Value float64 `json:"value"`
Err error Err error `json:"err"`
} }
// Float64PtrResult ... // Float64PtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:52 2023/5/16
type Float64PtrResult struct { type Float64PtrResult struct {
Value *float64 Value *float64 `json:"value"`
Err error Err error `json:"err"`
} }
// Any ... // Any ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:40 2023/5/8
type Any struct { type Any struct {
Value any Value any `json:"value"`
Err error Err error `json:"err"`
} }
// BoolResult ... // BoolResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:36 2023/5/8
type BoolResult struct { type BoolResult struct {
Value bool Value bool `json:"value"`
Err error Err error `json:"err"`
} }
// BoolPtrResult ... // BoolPtrResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:53 2023/5/16
type BoolPtrResult struct { type BoolPtrResult struct {
Value *bool Value *bool `json:"value"`
Err error Err error `json:"err"`
} }
// ObjectResult ... // ObjectResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:38 2023/5/8
type ObjectResult struct { type ObjectResult struct {
Value map[string]any Value map[string]any `json:"value"`
Err error Err error `json:"err"`
} }
// StringResult ... // StringResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:57 2023/5/8
type StringResult struct { type StringResult struct {
Value string Value string `json:"value"`
Err error Err error `json:"err"`
} }
// StringPtrResult 字符串指针 // StringPtrResult 字符串指针
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:02 2023/5/15
type StringPtrResult struct { type StringPtrResult struct {
Value *string Value *string `json:"value"`
Err error Err error `json:"err"`
} }
// Int8SliceResult ... // Int8SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:49 2023/5/8
type Int8SliceResult struct { type Int8SliceResult struct {
Value []int8 Value []int8 `json:"value"`
Err error Err error `json:"err"`
} }
// Int16SliceResult ... // Int16SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:49 2023/5/8
type Int16SliceResult struct { type Int16SliceResult struct {
Value []int16 Value []int16 `json:"value"`
Err error Err error `json:"err"`
} }
// Int32SliceResult ... // Int32SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:50 2023/5/8
type Int32SliceResult struct { type Int32SliceResult struct {
Value []int32 Value []int32 `json:"value"`
Err error Err error `json:"err"`
} }
// Int64SliceResult ... // Int64SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:50 2023/5/8
type Int64SliceResult struct { type Int64SliceResult struct {
Value []int64 Value []int64 `json:"value"`
Err error Err error `json:"err"`
} }
// IntSliceResult ... // IntSliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:50 2023/5/8
type IntSliceResult struct { type IntSliceResult struct {
Value []int Value []int `json:"value"`
Err error Err error `json:"err"`
} }
// Uint8SliceResult ... // Uint8SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:55 2023/5/8
type Uint8SliceResult struct { type Uint8SliceResult struct {
Value []uint8 Value []uint8 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint16SliceResult ... // Uint16SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:55 2023/5/8
type Uint16SliceResult struct { type Uint16SliceResult struct {
Value []uint16 Value []uint16 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint32SliceResult ... // Uint32SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:55 2023/5/8
type Uint32SliceResult struct { type Uint32SliceResult struct {
Value []uint32 Value []uint32 `json:"value"`
Err error Err error `json:"err"`
} }
// Uint64SliceResult ... // Uint64SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:55 2023/5/8
type Uint64SliceResult struct { type Uint64SliceResult struct {
Value []uint64 Value []uint64 `json:"value"`
Err error Err error `json:"err"`
} }
// UintSliceResult ... // UintSliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:56 2023/5/8
type UintSliceResult struct { type UintSliceResult struct {
Value []uint Value []uint `json:"value"`
Err error Err error `json:"err"`
} }
// BoolSliceResult ... // BoolSliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:22 2023/5/8
type BoolSliceResult struct { type BoolSliceResult struct {
Value []bool Value []bool `json:"value"`
Err error Err error `json:"err"`
} }
// Float32SliceResult ... // Float32SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:24 2023/5/8
type Float32SliceResult struct { type Float32SliceResult struct {
Value []float32 Value []float32 `json:"value"`
Err error Err error `json:"err"`
} }
// Float64SliceResult ... // Float64SliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:24 2023/5/8
type Float64SliceResult struct { type Float64SliceResult struct {
Value []float64 Value []float64 `json:"value"`
Err error Err error `json:"err"`
} }
// DurationResult 时间转换结果 // DurationResult 时间转换结果
//
// Author : zhangdeman001@ke.com<张德满>
//
// Date : 20:32 2023/9/4
type DurationResult struct { type DurationResult struct {
Value time.Duration Value time.Duration `json:"value"`
Err error Err error `json:"err"`
} }
// StringSliceResult ... // StringSliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:11 2023/8/6
type StringSliceResult struct { type StringSliceResult struct {
Value []string Value []string `json:"value"`
Err error Err error `json:"err"`
} }
// MapResult 转map的结果 // MapResult 转map的结果
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:05 2023/8/10
type MapResult struct { type MapResult struct {
Value Map Value Map `json:"value"`
Err error Err error `json:"err"`
} }
// AnySliceResult ... // AnySliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:28 2023/5/8
type AnySliceResult struct { type AnySliceResult struct {
Value []any Value []any `json:"value"`
Err error Err error `json:"err"`
} }

255
string.go
View File

@@ -11,20 +11,17 @@ import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"errors" "errors"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/axgle/mahonia"
"github.com/spaolacci/murmur3"
"io" "io"
"math/rand" "math/rand"
"strings" "strings"
"time" "time"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/axgle/mahonia"
"github.com/spaolacci/murmur3"
) )
// StringFromRandom 从随机字符串生成String // StringFromRandom 从随机字符串生成String
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:50 2023/8/11
func StringFromRandom(length int, sourceCharList string) String { func StringFromRandom(length int, sourceCharList string) String {
if length == 0 { if length == 0 {
return "" return ""
@@ -36,24 +33,16 @@ func StringFromRandom(length int, sourceCharList string) String {
strByte := []byte(sourceCharList) strByte := []byte(sourceCharList)
var genStrByte = make([]byte, 0) var genStrByte = make([]byte, 0)
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < int(length); i++ { for i := 0; i < length; i++ {
genStrByte = append(genStrByte, strByte[r.Intn(len(strByte))]) genStrByte = append(genStrByte, strByte[r.Intn(len(strByte))])
} }
return String(string(genStrByte)) return String(genStrByte)
} }
// String 字符串类型包装 // String 字符串类型包装
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:07 2023/5/5
type String string type String string
// ToFloat32 ... // ToFloat32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:26 2023/5/4
func (str String) ToFloat32() Float32Result { func (str String) ToFloat32() Float32Result {
var ( var (
res Float32Result res Float32Result
@@ -63,10 +52,6 @@ func (str String) ToFloat32() Float32Result {
} }
// ToFloat32Ptr ... // ToFloat32Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:58 2023/5/16
func (str String) ToFloat32Ptr() Float32PtrResult { func (str String) ToFloat32Ptr() Float32PtrResult {
res := str.ToFloat32() res := str.ToFloat32()
if nil != res.Err { if nil != res.Err {
@@ -82,10 +67,6 @@ func (str String) ToFloat32Ptr() Float32PtrResult {
} }
// ToFloat64 ... // ToFloat64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:26 2023/5/4
func (str String) ToFloat64() Float64Result { func (str String) ToFloat64() Float64Result {
var ( var (
res Float64Result res Float64Result
@@ -95,10 +76,6 @@ func (str String) ToFloat64() Float64Result {
} }
// ToFloat64Ptr ... // ToFloat64Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:59 2023/5/16
func (str String) ToFloat64Ptr() Float64PtrResult { func (str String) ToFloat64Ptr() Float64PtrResult {
res := str.ToFloat64() res := str.ToFloat64()
if nil != res.Err { if nil != res.Err {
@@ -114,46 +91,26 @@ func (str String) ToFloat64Ptr() Float64PtrResult {
} }
// ToDouble 转double // ToDouble 转double
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:33 2023/5/4
func (str String) ToDouble() Float64Result { func (str String) ToDouble() Float64Result {
return str.ToFloat64() return str.ToFloat64()
} }
// ToDoublePtr ... // ToDoublePtr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:59 2023/5/16
func (str String) ToDoublePtr() Float64PtrResult { func (str String) ToDoublePtr() Float64PtrResult {
return str.ToFloat64Ptr() return str.ToFloat64Ptr()
} }
// ToNumber 转数字, 使用最高精度的float64 // ToNumber 转数字, 使用最高精度的float64
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:33 2023/5/4
func (str String) ToNumber() Float64Result { func (str String) ToNumber() Float64Result {
return str.ToFloat64() return str.ToFloat64()
} }
// ToNumberPtr ... // ToNumberPtr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:00 2023/5/16
func (str String) ToNumberPtr() Float64PtrResult { func (str String) ToNumberPtr() Float64PtrResult {
return str.ToFloat64Ptr() return str.ToFloat64Ptr()
} }
// ToInt8 ... // ToInt8 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToInt8() Int8Result { func (str String) ToInt8() Int8Result {
var ( var (
res Int8Result res Int8Result
@@ -163,10 +120,6 @@ func (str String) ToInt8() Int8Result {
} }
// ToInt8Ptr ... // ToInt8Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:01 2023/5/16
func (str String) ToInt8Ptr() Int8PtrResult { func (str String) ToInt8Ptr() Int8PtrResult {
res := str.ToInt8() res := str.ToInt8()
if nil != res.Err { if nil != res.Err {
@@ -182,10 +135,6 @@ func (str String) ToInt8Ptr() Int8PtrResult {
} }
// ToInt16 ... // ToInt16 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToInt16() Int16Result { func (str String) ToInt16() Int16Result {
var ( var (
res Int16Result res Int16Result
@@ -195,10 +144,6 @@ func (str String) ToInt16() Int16Result {
} }
// ToInt16Ptr ... // ToInt16Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:02 2023/5/16
func (str String) ToInt16Ptr() Int16PtrResult { func (str String) ToInt16Ptr() Int16PtrResult {
res := str.ToInt16() res := str.ToInt16()
if nil != res.Err { if nil != res.Err {
@@ -214,10 +159,6 @@ func (str String) ToInt16Ptr() Int16PtrResult {
} }
// ToInt32 ... // ToInt32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToInt32() Int32Result { func (str String) ToInt32() Int32Result {
var ( var (
res Int32Result res Int32Result
@@ -227,10 +168,6 @@ func (str String) ToInt32() Int32Result {
} }
// ToInt32Ptr ... // ToInt32Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:03 2023/5/16
func (str String) ToInt32Ptr() Int32PtrResult { func (str String) ToInt32Ptr() Int32PtrResult {
res := str.ToInt32() res := str.ToInt32()
if nil != res.Err { if nil != res.Err {
@@ -246,10 +183,6 @@ func (str String) ToInt32Ptr() Int32PtrResult {
} }
// ToInt64 ... // ToInt64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToInt64() Int64Result { func (str String) ToInt64() Int64Result {
var ( var (
res Int64Result res Int64Result
@@ -259,10 +192,6 @@ func (str String) ToInt64() Int64Result {
} }
// ToInt64Ptr ... // ToInt64Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:03 2023/5/16
func (str String) ToInt64Ptr() Int64PtrResult { func (str String) ToInt64Ptr() Int64PtrResult {
res := str.ToInt64() res := str.ToInt64()
if nil != res.Err { if nil != res.Err {
@@ -278,10 +207,6 @@ func (str String) ToInt64Ptr() Int64PtrResult {
} }
// ToInt ... // ToInt ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:47 2023/5/5
func (str String) ToInt() IntResult { func (str String) ToInt() IntResult {
var ( var (
res IntResult res IntResult
@@ -310,10 +235,6 @@ func (str String) ToIntPtr() IntPtrResult {
} }
// ToUint8 ... // ToUint8 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:30 2023/5/4
func (str String) ToUint8() Uint8Result { func (str String) ToUint8() Uint8Result {
var ( var (
res Uint8Result res Uint8Result
@@ -323,10 +244,6 @@ func (str String) ToUint8() Uint8Result {
} }
// ToUint8Ptr ... // ToUint8Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:05 2023/5/16
func (str String) ToUint8Ptr() Uint8PtrResult { func (str String) ToUint8Ptr() Uint8PtrResult {
res := str.ToUint8() res := str.ToUint8()
if nil != res.Err { if nil != res.Err {
@@ -342,10 +259,6 @@ func (str String) ToUint8Ptr() Uint8PtrResult {
} }
// ToUint16 ... // ToUint16 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToUint16() Uint16Result { func (str String) ToUint16() Uint16Result {
var ( var (
res Uint16Result res Uint16Result
@@ -355,10 +268,6 @@ func (str String) ToUint16() Uint16Result {
} }
// ToUint16Ptr ... // ToUint16Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:05 2023/5/16
func (str String) ToUint16Ptr() Uint16PtrResult { func (str String) ToUint16Ptr() Uint16PtrResult {
res := str.ToUint16() res := str.ToUint16()
if nil != res.Err { if nil != res.Err {
@@ -374,10 +283,6 @@ func (str String) ToUint16Ptr() Uint16PtrResult {
} }
// ToUint32 ... // ToUint32 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToUint32() Uint32Result { func (str String) ToUint32() Uint32Result {
var ( var (
res Uint32Result res Uint32Result
@@ -387,10 +292,6 @@ func (str String) ToUint32() Uint32Result {
} }
// ToUint32Ptr ... // ToUint32Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:05 2023/5/16
func (str String) ToUint32Ptr() Uint32PtrResult { func (str String) ToUint32Ptr() Uint32PtrResult {
res := str.ToUint32() res := str.ToUint32()
if nil != res.Err { if nil != res.Err {
@@ -406,10 +307,6 @@ func (str String) ToUint32Ptr() Uint32PtrResult {
} }
// ToUint64 ... // ToUint64 ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToUint64() Uint64Result { func (str String) ToUint64() Uint64Result {
var ( var (
res Uint64Result res Uint64Result
@@ -419,10 +316,6 @@ func (str String) ToUint64() Uint64Result {
} }
// ToUint64Ptr ... // ToUint64Ptr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:06 2023/5/16
func (str String) ToUint64Ptr() Uint64PtrResult { func (str String) ToUint64Ptr() Uint64PtrResult {
res := str.ToUint64() res := str.ToUint64()
if nil != res.Err { if nil != res.Err {
@@ -438,10 +331,6 @@ func (str String) ToUint64Ptr() Uint64PtrResult {
} }
// ToUint ... // ToUint ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:29 2023/5/4
func (str String) ToUint() UintResult { func (str String) ToUint() UintResult {
var ( var (
res UintResult res UintResult
@@ -451,10 +340,6 @@ func (str String) ToUint() UintResult {
} }
// ToUintPtr ... // ToUintPtr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:06 2023/5/16
func (str String) ToUintPtr() UintPtrResult { func (str String) ToUintPtr() UintPtrResult {
res := str.ToUint() res := str.ToUint()
if nil != res.Err { if nil != res.Err {
@@ -470,10 +355,6 @@ func (str String) ToUintPtr() UintPtrResult {
} }
// ToBool ... // ToBool ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:34 2023/5/4
func (str String) ToBool() BoolResult { func (str String) ToBool() BoolResult {
var ( var (
res BoolResult res BoolResult
@@ -483,10 +364,6 @@ func (str String) ToBool() BoolResult {
} }
// ToBoolPtr ... // ToBoolPtr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:07 2023/5/16
func (str String) ToBoolPtr() BoolPtrResult { func (str String) ToBoolPtr() BoolPtrResult {
res := str.ToBool() res := str.ToBool()
if nil != res.Err { if nil != res.Err {
@@ -502,10 +379,6 @@ func (str String) ToBoolPtr() BoolPtrResult {
} }
// ToStringPtr 转换成字符串指针 // ToStringPtr 转换成字符串指针
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:57 2023/7/3
func (str String) ToStringPtr() StringPtrResult { func (str String) ToStringPtr() StringPtrResult {
val := str.Value() val := str.Value()
return StringPtrResult{ return StringPtrResult{
@@ -531,10 +404,6 @@ func (str String) ToObject() ObjectResult {
} }
// ToStruct ... // ToStruct ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:38 2023/5/4
func (str String) ToStruct(receiver any) error { func (str String) ToStruct(receiver any) error {
if nil == receiver { if nil == receiver {
return errors.New("receiver is nil") return errors.New("receiver is nil")
@@ -543,10 +412,6 @@ func (str String) ToStruct(receiver any) error {
} }
// ToInt8Slice ... // ToInt8Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:55 2023/5/4
func (str String) ToInt8Slice(splitChar ...string) Int8SliceResult { func (str String) ToInt8Slice(splitChar ...string) Int8SliceResult {
result := Int8SliceResult{ result := Int8SliceResult{
Value: []int8{}, Value: []int8{},
@@ -575,10 +440,6 @@ func (str String) ToInt8Slice(splitChar ...string) Int8SliceResult {
} }
// ToInt16Slice ... // ToInt16Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:01 2023/5/4
func (str String) ToInt16Slice(splitChar ...string) Int16SliceResult { func (str String) ToInt16Slice(splitChar ...string) Int16SliceResult {
result := Int16SliceResult{ result := Int16SliceResult{
@@ -606,10 +467,6 @@ func (str String) ToInt16Slice(splitChar ...string) Int16SliceResult {
} }
// ToInt32Slice ... // ToInt32Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:03 2023/5/4
func (str String) ToInt32Slice(splitChar ...string) Int32SliceResult { func (str String) ToInt32Slice(splitChar ...string) Int32SliceResult {
result := Int32SliceResult{ result := Int32SliceResult{
Value: []int32{}, Value: []int32{},
@@ -636,10 +493,6 @@ func (str String) ToInt32Slice(splitChar ...string) Int32SliceResult {
} }
// ToInt64Slice ... // ToInt64Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:04 2023/5/4
func (str String) ToInt64Slice(splitChar ...string) Int64SliceResult { func (str String) ToInt64Slice(splitChar ...string) Int64SliceResult {
result := Int64SliceResult{ result := Int64SliceResult{
Value: []int64{}, Value: []int64{},
@@ -665,10 +518,6 @@ func (str String) ToInt64Slice(splitChar ...string) Int64SliceResult {
} }
// ToIntSlice ... // ToIntSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:04 2023/5/4
func (str String) ToIntSlice(splitChar ...string) IntSliceResult { func (str String) ToIntSlice(splitChar ...string) IntSliceResult {
result := IntSliceResult{ result := IntSliceResult{
Value: []int{}, Value: []int{},
@@ -695,10 +544,6 @@ func (str String) ToIntSlice(splitChar ...string) IntSliceResult {
} }
// ToUint8Slice ... // ToUint8Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:50 2023/5/5
func (str String) ToUint8Slice(splitChar ...string) Uint8SliceResult { func (str String) ToUint8Slice(splitChar ...string) Uint8SliceResult {
result := Uint8SliceResult{ result := Uint8SliceResult{
Value: []uint8{}, Value: []uint8{},
@@ -725,10 +570,6 @@ func (str String) ToUint8Slice(splitChar ...string) Uint8SliceResult {
} }
// ToUint16Slice ... // ToUint16Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:52 2023/5/5
func (str String) ToUint16Slice(splitChar ...string) Uint16SliceResult { func (str String) ToUint16Slice(splitChar ...string) Uint16SliceResult {
result := Uint16SliceResult{ result := Uint16SliceResult{
Value: []uint16{}, Value: []uint16{},
@@ -755,10 +596,6 @@ func (str String) ToUint16Slice(splitChar ...string) Uint16SliceResult {
} }
// ToUint32Slice ... // ToUint32Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:53 2023/5/5
func (str String) ToUint32Slice(splitChar ...string) Uint32SliceResult { func (str String) ToUint32Slice(splitChar ...string) Uint32SliceResult {
result := Uint32SliceResult{ result := Uint32SliceResult{
Value: []uint32{}, Value: []uint32{},
@@ -785,10 +622,6 @@ func (str String) ToUint32Slice(splitChar ...string) Uint32SliceResult {
} }
// ToUint64Slice ... // ToUint64Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:54 2023/5/5
func (str String) ToUint64Slice(splitChar ...string) Uint64SliceResult { func (str String) ToUint64Slice(splitChar ...string) Uint64SliceResult {
result := Uint64SliceResult{ result := Uint64SliceResult{
Value: []uint64{}, Value: []uint64{},
@@ -814,10 +647,6 @@ func (str String) ToUint64Slice(splitChar ...string) Uint64SliceResult {
} }
// ToUintSlice ... // ToUintSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:54 2023/5/5
func (str String) ToUintSlice(splitChar ...string) UintSliceResult { func (str String) ToUintSlice(splitChar ...string) UintSliceResult {
result := UintSliceResult{ result := UintSliceResult{
Value: []uint{}, Value: []uint{},
@@ -844,10 +673,6 @@ func (str String) ToUintSlice(splitChar ...string) UintSliceResult {
} }
// ToBoolSlice ... // ToBoolSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:55 2023/5/5
func (str String) ToBoolSlice(splitChar ...string) BoolSliceResult { func (str String) ToBoolSlice(splitChar ...string) BoolSliceResult {
result := BoolSliceResult{ result := BoolSliceResult{
Value: []bool{}, Value: []bool{},
@@ -874,10 +699,6 @@ func (str String) ToBoolSlice(splitChar ...string) BoolSliceResult {
} }
// ToFloat32Slice ... // ToFloat32Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:56 2023/5/5
func (str String) ToFloat32Slice(splitChar ...string) Float32SliceResult { func (str String) ToFloat32Slice(splitChar ...string) Float32SliceResult {
result := Float32SliceResult{ result := Float32SliceResult{
Value: []float32{}, Value: []float32{},
@@ -903,10 +724,6 @@ func (str String) ToFloat32Slice(splitChar ...string) Float32SliceResult {
} }
// ToFloat64Slice ... // ToFloat64Slice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:56 2023/5/5
func (str String) ToFloat64Slice(splitChar ...string) Float64SliceResult { func (str String) ToFloat64Slice(splitChar ...string) Float64SliceResult {
result := Float64SliceResult{ result := Float64SliceResult{
Value: []float64{}, Value: []float64{},
@@ -933,28 +750,16 @@ func (str String) ToFloat64Slice(splitChar ...string) Float64SliceResult {
} }
// ToDoubleSlice ... // ToDoubleSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:57 2023/5/5
func (str String) ToDoubleSlice(splitChar ...string) Float64SliceResult { func (str String) ToDoubleSlice(splitChar ...string) Float64SliceResult {
return str.ToFloat64Slice(splitChar...) return str.ToFloat64Slice(splitChar...)
} }
// ToNumberSlice ... // ToNumberSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 10:57 2023/5/5
func (str String) ToNumberSlice(splitChar ...string) Float64SliceResult { func (str String) ToNumberSlice(splitChar ...string) Float64SliceResult {
return str.ToFloat64Slice(splitChar...) return str.ToFloat64Slice(splitChar...)
} }
// ToDuration 转换为时间格式 // ToDuration 转换为时间格式
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:31 2023/9/4
func (str String) ToDuration(timeUnit time.Duration) DurationResult { func (str String) ToDuration(timeUnit time.Duration) DurationResult {
int64Val := str.ToInt64() int64Val := str.ToInt64()
if nil != int64Val.Err { if nil != int64Val.Err {
@@ -967,10 +772,6 @@ func (str String) ToDuration(timeUnit time.Duration) DurationResult {
} }
// ToStringSlice ... // ToStringSlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:11 2023/8/6
func (str String) ToStringSlice(splitChar ...string) StringSliceResult { func (str String) ToStringSlice(splitChar ...string) StringSliceResult {
result := StringSliceResult{ result := StringSliceResult{
Value: []string{}, Value: []string{},
@@ -987,10 +788,6 @@ func (str String) ToStringSlice(splitChar ...string) StringSliceResult {
} }
// ToAnySlice ... // ToAnySlice ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:01 2023/5/5
func (str String) ToAnySlice(splitCharList ...string) AnySliceResult { func (str String) ToAnySlice(splitCharList ...string) AnySliceResult {
result := AnySliceResult{ result := AnySliceResult{
Value: []any{}, Value: []any{},
@@ -1023,10 +820,6 @@ func (str String) ToAnySlice(splitCharList ...string) AnySliceResult {
} }
// Md5 计算Md5值 // Md5 计算Md5值
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:08 2023/5/16
func (str String) Md5() StringResult { func (str String) Md5() StringResult {
h := md5.New() h := md5.New()
_, err := io.WriteString(h, str.Value()) _, err := io.WriteString(h, str.Value())
@@ -1043,19 +836,11 @@ func (str String) Md5() StringResult {
} }
// Value ... // Value ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:11 2023/5/16
func (str String) Value() string { func (str String) Value() string {
return string(str) return string(str)
} }
// GetLetterList 获取字母列表 // GetLetterList 获取字母列表
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:53 2023/8/11
func (str String) GetLetterList() []string { func (str String) GetLetterList() []string {
return []string{ return []string{
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
@@ -1064,10 +849,6 @@ func (str String) GetLetterList() []string {
} }
// SnakeCaseToCamel 蛇形字符串转换为驼峰 // SnakeCaseToCamel 蛇形字符串转换为驼峰
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:58 下午 2021/10/25
func (str String) SnakeCaseToCamel() string { func (str String) SnakeCaseToCamel() string {
if len(str) == 0 { if len(str) == 0 {
return "" return ""
@@ -1097,10 +878,6 @@ func (str String) SnakeCaseToCamel() string {
} }
// Convert 字符串编码转换 // Convert 字符串编码转换
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:38 2022/7/9
func (str String) Convert(sourceCode string, targetCode string) String { func (str String) Convert(sourceCode string, targetCode string) String {
sourceCoder := mahonia.NewDecoder(sourceCode) sourceCoder := mahonia.NewDecoder(sourceCode)
sourceResult := sourceCoder.ConvertString(str.Value()) sourceResult := sourceCoder.ConvertString(str.Value())
@@ -1110,10 +887,6 @@ func (str String) Convert(sourceCode string, targetCode string) String {
} }
// ClearChar 清理指定字符 // ClearChar 清理指定字符
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:59 2023/8/11
func (str String) ClearChar(charList ...string) String { func (str String) ClearChar(charList ...string) String {
if len(charList) == 0 { if len(charList) == 0 {
return str return str
@@ -1126,10 +899,6 @@ func (str String) ClearChar(charList ...string) String {
} }
// ReplaceChineseChar 替换常见的中文符号 // ReplaceChineseChar 替换常见的中文符号
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:59 2023/4/4
func (str String) ReplaceChineseChar() String { func (str String) ReplaceChineseChar() String {
charTable := map[string]string{ charTable := map[string]string{
"": "(", "": "(",
@@ -1144,10 +913,6 @@ func (str String) ReplaceChineseChar() String {
} }
// ReplaceChar 替换指定字符 // ReplaceChar 替换指定字符
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:01 2023/8/11
func (str String) ReplaceChar(charTable map[string]string) String { func (str String) ReplaceChar(charTable map[string]string) String {
if len(charTable) == 0 { if len(charTable) == 0 {
return str return str
@@ -1160,10 +925,6 @@ func (str String) ReplaceChar(charTable map[string]string) String {
} }
// HasSubStr 是否包含指定的子串 // HasSubStr 是否包含指定的子串
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:37 2024/4/19
func (str String) HasSubStr(subStrList []string) bool { func (str String) HasSubStr(subStrList []string) bool {
if len(subStrList) == 0 { if len(subStrList) == 0 {
return true return true
@@ -1178,10 +939,6 @@ func (str String) HasSubStr(subStrList []string) bool {
} }
// HashNumber ... // HashNumber ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:05 2024/6/27
func (str String) HashNumber() Uint64Result { func (str String) HashNumber() Uint64Result {
return Uint64Result{ return Uint64Result{
Value: murmur3.Sum64([]byte(str.Value())), Value: murmur3.Sum64([]byte(str.Value())),