goutils

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: MIT Imports: 16 Imported by: 1

README

goutils

golang一些常用工具类封装

emoji
func EmojiFilter(content string) (newContent string)

函数EmojiFilter过滤掉字符串中的Emoji 。入参content为string类型;返回一个新的字符串,类型为string。

file
func GetPathAllFile(pathname string) (files []string, err error)

函数GetPathAllFile获取路径pathname下面所有的文件 。入参pathname为文件类型;返回文件路径切片。

ip
func RemoteIp(req *http.Request) string

函数RemoteIp获取远程客户端的IP。入参req为http包中http.Request。

func Ip2long(ipStr string) uint32

函数Ip2long将IPv4字符串形式转为uint32。

money
func FenToYuanFloat(money int) float64

函数FenToYuanFloat将金额分转换成元。入参money分值为分,类型为int;返回参数是元,类型为float64。

func FenToYuanString(money int) string 

函数FenToYuanString将金额分转换成元。入参money为金额分,类型为int;返回参数是元,类型为string。

func YuanToFen(money float64) int64

函数YuanToFen将金额元转换为分。入参money为金额元,为float64类型;返回参数是分,类型为int64。

func YuanToFenRounding(money float64) int64

函数YuanToFenRounding将金额元转换为分。它与YuanToFen不同的是,它满足当乘以100后,仍然有小数位,四舍五入法后,再取整数部分。

func DiscountCalculation(realMoney, tagPrice float64) string

函数DiscountCalculation计算两个价格的折扣。入参realMoney为实际价格,tagPrice为吊牌价格,均是float64类型;返回参数是入参两者对应的折扣,返回值类型为string(保留一位小数)。

func DiscountCalculationInt(realMoney, tagPrice int) string

函数DiscountCalculation计算两个价格的折扣。与DiscountCalculation不同的是传入的参数类型。

random

注意:使用random包内的方法时,请确保项目初始化时设置随机数种子,如:rand.Seed(time.Now().UnixNano())。

func GetRandomIp() string

函数GetRandomIp获取国内随机Ip。返回参数Ip为string类型。

func GetRandomString(n int) string

函数GetRandomString随机生成大写字母和数字的组合。入参n是生成字符串的长度,类型为int;返回参数是随机数字,类型为string。

time
func TimeFormatter(i interface{}, format string) string

函数TimeFormatter为时间格式化函数,将对应时间进行格式化。 入参i为时间,请传入time、int、int32、int64类型; 入参format为需要格式化的日期格式,如:2006-01-02 15:04:05、2006.01.02等等;返回参数为格式化后的时间,类型为string。

func GetTodayStartTime(formatLayout string) time.Time

函数GetTodayStartTime获取本日起始时间。 入参formatLayout为格式化格式,类型为string;返回参数是今日起始时间,类型为time.Time。

func IsYesterday(t int64) bool

函数IsYesterday判断传入的时间t是否为昨天。返回参数为bool类型。

func IsTomorrow(t int64) bool

函数IsTomorrow判断传入的时间t是否为明天。返回参数为bool类型。

func IsToday(t int64) bool

函数IsToday判断传入的时间t是否为今天。返回参数为bool类型。

func TimeAgo(t time.Time) string

函数TimeAgo判断传入的时间t是多长时间前。

func IsLeap(year int) bool

函数IsLeap判断年份year是否为闰年。

verify
func MobilePhoneValidate(phoneNumber string) bool

函数MobilePhoneValidate校验传入的手机号是否正确。入参phoneNumber为手机号,类型为string;返回参数为bool类型。

func IdCardValidate(idCardNumber string) bool

函数IdCardValidate校验传入的身份证号码是否正确。入参idCardNumber为身份证号码,类型为string;返回参数为bool类型。

Documentation

Index

Constants

View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
)
View Source
const (
	HttpContentTypeForm = "application/x-www-form-urlencoded"
)

Variables

View Source
var IpLong = [][]int{
	{607649792, 608174079},
	{975044608, 977272831},
	{999751680, 999784447},
	{1019346944, 1019478015},
	{1038614528, 1039007743},
	{1783627776, 1784676351},
	{1947009024, 1947074559},
	{1987051520, 1988034559},
	{2035023872, 2035154943},
	{2078801920, 2079064063},
	{-1950089216, -1948778497},
	{-1425539072, -1425014785},
	{-1236271104, -1235419137},
	{-770113536, -768606209},
	{-569376768, -564133889},
}

Functions

func DiscountCalculation

func DiscountCalculation(realMoney, tagPrice float64) string

DiscountCalculation计算折扣. realMoney实际价格,tagPrice吊牌价.

func DiscountCalculationInt

func DiscountCalculationInt(realMoney, tagPrice int) string

DiscountCalculationInt计算折扣. realMoney实际价格,tagPrice吊牌价.

func EmojiFilter

func EmojiFilter(content string) (newContent string)

EmojiFilter过滤掉传入的字符串content中的Emoji

func FenToYuanFloat

func FenToYuanFloat(money int) float64

FenToYuanFloat将金额分转换成元. 返回一个float64类型.

func FenToYuanString

func FenToYuanString(money int) string

FenToYuanString将金额分转换成元. 返回一个string类型.

func GetPathAllFile

func GetPathAllFile(pathname string) (files []string, err error)

GetPathAllFile获取路径下面所有文件

func GetRandomIp

func GetRandomIp() string

GetRandomIp生成国内随机Ip.

func GetRandomString

func GetRandomString(n int) string

GetRandomString随机生成大写字母和数字的组合. n是生成字符串的长度.

func GetTodayStartTime

func GetTodayStartTime(formatLayout string) time.Time

GetTodayStartTime获取本日起始时间. formatLayout为格式化格式.

func HttpGet

func HttpGet(url string) ([]byte, error)

func HttpPost

func HttpPost(url, contentType string, reqBody string) ([]byte, error)

func IdCardValidate

func IdCardValidate(idCardNumber string) bool

IdCardValidate校验传入的身份证号码是否正确.

func Ip2long

func Ip2long(ipStr string) uint32

Ip2long将IPv4字符串形式转为uint32

func IsLeap

func IsLeap(year int) bool

IsLeap判断年份year是否为闰年.

func IsToday

func IsToday(t int64) bool

IsToday判断传入的时间t是否为今天.

func IsTomorrow

func IsTomorrow(t int64) bool

IsTomorrow判断传入的时间t是否为明天.

func IsYesterday

func IsYesterday(t int64) bool

IsYesterday判断传入的时间t是否为昨天.

func JsonMarshalNoError

func JsonMarshalNoError(data interface{}) string

func MobilePhoneValidate

func MobilePhoneValidate(phoneNumber string) bool

MobilePhoneValidate校验传入的手机号是否正确.

func RandInt64

func RandInt64(min, max int64) int64

func RemoteIp

func RemoteIp(req *http.Request) string

RemoteIp返回远程客户端的IP,如 192.168.1.1

func TimeAgo

func TimeAgo(t time.Time) string

TimeAgo判断传入的时间t是多长时间前.

func TimeFormatter

func TimeFormatter(i interface{}, format string) string

TimeFormatter为时间格式化函数. i请传入time、int、int32、int64类型. format为需要格式化的日期格式 如:2006-01-02 15:04:05、2006.01.02等等.

func YuanToFen

func YuanToFen(money float64) int64

YuanToFen将金额元转换为分. 如果需要四舍五入,请使用YuanToFenRounding.

func YuanToFenRounding

func YuanToFenRounding(money float64) int64

YuanToFenRounding将金额元转换为分. 它满足:当乘以100后,仍然有小数位,四舍五入法后,再取整数部分.

Types

This section is empty.

Jump to

Keyboard shortcuts

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