saData

package
v0.0.0-...-b2602dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 20 Imported by: 5

README

数据处理

注意事项
  • 开发过程中,saData包不能引用go-utils任何包
sa_check
  • 支持的tag标签:

    "> >= < <= <>" 长度校验:字符串,校验rune长度;整形则对比数值
    "required" 必要参数
    "enum(1:激活,2:废弃) in(1,2) in(ms,md)" 枚举
    "phone" 校验手机格式

  • tag示例: type:"phone;required;in(ms,md);<=23"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeSource = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ" //方便给人识别的编码

Functions

func AppendId

func AppendId(ary []int64, id int64) []int64

注意:只支持基础类型数据,会排除已存在的

func AppendStr

func AppendStr(ary []string, str string) []string

func AryStructName

func AryStructName(ary interface{}) (string, error)

func AryToIds

func AryToIds(ary []int64, fullComma bool) string

AryToIds fullComma为true时: []{1,2,3} => ,1,2,3, fullComma为false时: []{1,2,3} => 1,2,3

func Btos

func Btos(b bool) string

func BytesToModel

func BytesToModel(b []byte, m interface{}) error

func BytesToStr

func BytesToStr(b []byte) string

func CamelStr

func CamelStr(s string) string
下划线命名转化为小驼峰命名

xx_yy to xxYy

func CharToId

func CharToId(str string) int64

func CharToIdWithSource

func CharToIdWithSource(str string, source string) int64

func CodeToId

func CodeToId(code string, length int) (id int64)

func CodeToIdWithSource

func CodeToIdWithSource(code string, length int, source []string) (id int64)

func ContainStrs

func ContainStrs(item string, ary []string) (exist bool)

func DecodeBase64

func DecodeBase64(s string) string

func EncodeBase64

func EncodeBase64(s string) string

func F32tos

func F32tos(f float32) string

func Fen2Yuan

func Fen2Yuan(fen interface{}, roundType ...RoundType) (yuan float64)

Fen2Yuan 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式 返回的元是2位小数

func Float64

func Float64(d interface{}) float64

func FloatToInt64

func FloatToInt64(value interface{}, digit int, roundType ...RoundType) int64

FloatToInt 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式 digit是小数点后位数

func FormatIds

func FormatIds(str string) string

FormatIds 前后加逗号是为了方便SQL查询过滤 1,2,3 => ,1,2,3,

func GetIdByKeys

func GetIdByKeys(args map[string]interface{}, key1 string, key2 string) int64

func GetSuffix

func GetSuffix(s string) string

func I64tos

func I64tos(i int64) string

func IdToChar

func IdToChar(v int64) string

func IdToCharWithSource

func IdToCharWithSource(v int64, minLen int, source string) string

func IdToCode

func IdToCode(id int64, length int) (code string)

func IdToCodeWithSource

func IdToCodeWithSource(id int64, length int, source []string) (code string)

func IdsToAry

func IdsToAry(str string) []int64

IdsToAry 去零、去重 1,2,3 => []{1,2,3}

func InArray

func InArray(item interface{}, ary interface{}) (exist bool)

InArray 注意:只支持基础类型数据

func InArrayFun

func InArrayFun(ary interface{}, fun func(i int) bool) bool

func InStrs

func InStrs(item string, ary []string) (exist bool)

func Int

func Int(d interface{}) int

func Int64

func Int64(d interface{}) int64

func IntToFloat

func IntToFloat(value interface{}, digit int, roundType ...RoundType) float32

IntToFloat 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式 digit是小数点后位数

func IsImg

func IsImg(url string) bool

根据后缀判断是否是图片

func IsPhone

func IsPhone(str string) bool

func IsVideo

func IsVideo(url string) bool

根据后缀判断是否是视频

func Itos

func Itos(i int) string

func JoinStr

func JoinStr(org string, elems ...string) string

JoinString 字符串拼接 通过strings.Builder,效率更高

func LenCheck

func LenCheck(m interface{}, max int) error

rune长度,支持中文

func Li2Yuan

func Li2Yuan(li interface{}, roundType ...RoundType) (yuan float64)

Li2Yuan 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式 返回的元是3位小数

func MapToXml

func MapToXml(m *map[string]string) string

func Md5

func Md5(s string, lowercase bool) string

Md5 32位 lowercase = true 小写格式,否则大写

func ModifySysFilePath

func ModifySysFilePath(f string) string

func Qian2Yuan

func Qian2Yuan(qian interface{}, roundType ...RoundType) (yuan float64)

Qian2Yuan 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式 返回的元是3位小数

func RandomStr

func RandomStr() string

* 返回13位字符串

func RoundFloat32

func RoundFloat32(f float32, n int) float32

func RoundFloat64

func RoundFloat64(f float64, n int) float64

func RoundYuan

func RoundYuan(yuan interface{}, roundType ...RoundType) float64

RoundYuan 格式化,解决小数点问题 提供四舍五入、上下取整方式 返回的元是2位小数

func SQLColumn

func SQLColumn(str string) string

SQLColumn 删除字符串里有影响SQL的字符

func Sha256

func Sha256(s string, secret string, lowercase bool) string

Sha256 lowercase = true 小写格式,否则大写

func SnakeStr

func SnakeStr(s string) string
下划线命名转为大驼峰命名

XxYy to xx_yy , XxYY to xx_yy

func Split

func Split(s, sep string) []string

Split 去空、去重 1,2,3 => []{"1","2","3"}

func Stoi

func Stoi(s string) (int, error)

func Stoi16

func Stoi16(s string) (int16, error)

func Stoi32

func Stoi32(s string) (int32, error)

func Stoi64

func Stoi64(s string) (int64, error)

func Stoui32

func Stoui32(s string) (uint32, error)

func StrLen

func StrLen(s string) int

rune长度

func StrToBytes

func StrToBytes(s string) []byte

通过内存操作,效率极高,但是有风险。只在数据量很大、效率要求高的场景使用

func StrToData

func StrToData(str string) (interface{}, error)

func StrToModel

func StrToModel(str string, m interface{}) error

func String

func String(data interface{}) string

func StructElemValue

func StructElemValue(obj interface{}, k string) reflect.Value

func StructName

func StructName(obj interface{}) (string, error)

func SubIndex

func SubIndex(s string, sub string) int

func SubStr

func SubStr(s string, start int, cnt int) string

func ToAry

func ToAry(data interface{}) ([]interface{}, error)

func ToBool

func ToBool(d interface{}) (bool, error)

func ToBytes

func ToBytes(data interface{}) ([]byte, error)

func ToFloat32

func ToFloat32(d interface{}) (float32, error)

func ToFloat64

func ToFloat64(d interface{}) (float64, error)

func ToIds

func ToIds(ary interface{}, fullComma bool) string

ToIds fullComma为true时: []{1,2,3} => ,1,2,3, fullComma为false时: []{1,2,3} => 1,2,3 ary支持类型:[]string []int64 []int

func ToInt

func ToInt(d interface{}) (int, error)

func ToInt32

func ToInt32(d interface{}) (int32, error)

func ToInt64

func ToInt64(d interface{}) (int64, error)

func ToInt64Ary

func ToInt64Ary(data interface{}) ([]int64, error)

func ToInt8

func ToInt8(d interface{}) (int8, error)

func ToMap

func ToMap(data interface{}) (map[string]interface{}, error)

func ToMapAry

func ToMapAry(data interface{}) ([]map[string]interface{}, error)

func ToSQLIds

func ToSQLIds(ary []string) string

ToSQLIds

[]{'1','2','3'} => '1','2','3'

func ToStr

func ToStr(data interface{}) (string, error)

func ToStrAry

func ToStrAry(data interface{}) ([]string, error)

func ToStrMap

func ToStrMap(data interface{}) (map[string]string, error)

func TrimH5Tags

func TrimH5Tags(src string) (str string)
去除字符串中H5的style、script;

将标签转换为回车,去除连续回车,去除每段开始、结尾空格

func TrimPreSuffixSpace

func TrimPreSuffixSpace(s string) string

去除 ' ' '\n' '\r' '\t' 前缀和后缀

func TrimPrefixSpace

func TrimPrefixSpace(s string) string

去除 ' ' '\n' '\r' '\t'前缀,如果有多个也会去除

func TrimSpace

func TrimSpace(s string) string

去除所有 ' ' '\n' '\r' '\t'

func TrimSuffixSpace

func TrimSuffixSpace(s string) string

去除 ' ' '\n' '\r' '\t'后缀,如果有多个也会去除

func ValidCheck

func ValidCheck(ptr interface{}) (err error)

验证参数

func ValueToMap

func ValueToMap(v reflect.Value) *map[string]interface{}

func XmlToMap

func XmlToMap(s string) (map[string]interface{}, error)

func Yuan2Fen

func Yuan2Fen(yuan interface{}, roundType ...RoundType) (fen int64)

Yuan2Fen 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式

func Yuan2Li

func Yuan2Li(yuan interface{}, roundType ...RoundType) (li int64)

Yuan2Li 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式

func Yuan2Qian

func Yuan2Qian(yuan interface{}, roundType ...RoundType) (li int64)

Yuan2Qian 解决精度丢失问题 例如:19.9 * 100 = 1889 提供四舍五入、上下取整方式

Types

type NullInt

type NullInt struct {
	V  int
	Ok bool
}

type NullInt64

type NullInt64 struct {
	V  int64
	Ok bool
}

type NullString

type NullString struct {
	V  string
	Ok bool
}

type RoundType

type RoundType int8
const (
	RoundTypeDefault RoundType = iota //四舍五入
	RoundTypeUp                       //向上取整 取2位小数 如:1.234 => 1.24  1.238 => 1.24
	RoundTypeDown                     //向下取整 取2位小数 如:1.234 => 1.23  1.238 => 1.23
)

type StringMap

type StringMap map[string]string

func (StringMap) MarshalXML

func (m StringMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*StringMap) UnmarshalXML

func (m *StringMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

Directories

Path Synopsis
Package saError 一般建议: 各项目自行定义code值及对应的返回给前端的错误信息 业务代码内不固定错误文案 Msg是错误信息,只打印到日志
Package saError 一般建议: 各项目自行定义code值及对应的返回给前端的错误信息 业务代码内不固定错误文案 Msg是错误信息,只打印到日志

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL