web

package module
v0.0.0-...-0e6d7d3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: BSD-2-Clause Imports: 17 Imported by: 0

README

web

my webcraft

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPhoneNumber = fmt.Errorf("invalid phone number")
View Source
var RELEASE = os.Getenv("RELEASE") == "1"

if production enviroment

View Source
var VALID_ADCODE_PATTERN = regexp.MustCompile("^[0-9]{6,8}$")

Functions

func AbsInt64

func AbsInt64(d int64) int64

func AddInt64Set

func AddInt64Set(array []int64, d int64) []int64

func AddIntSet

func AddIntSet(array []int, d int) []int

func BoolToInt

func BoolToInt(b bool) int

func ChoiceInt64

func ChoiceInt64(src []int64) int64

随机选取一条

func ChoiceInts

func ChoiceInts(src []int) int

func CleanPath

func CleanPath(path string) string

func CmpAndroidVersion

func CmpAndroidVersion(v1, v2 string) int

比较安卓app_version

func CmpAppleVersion

func CmpAppleVersion(v1, v2 string) int

比较苹果app_version

func CmpInt64s

func CmpInt64s(a, b []int64) int

func Day

func Day(t time.Time) string

今日ymd

func DayDiff

func DayDiff(a, b int) int

两个时间戳的日期相减差多少天 a-b

func Double2dp

func Double2dp(n float64) float64

保留两位小数(keep 2 decimal places)

func FileExists

func FileExists(path string) bool

func FileMd5String

func FileMd5String(f io.Reader) string

func Float2dp

func Float2dp(n float32) float32

保留两位小数(keep 2 decimal places)

func FormatCityCode

func FormatCityCode(code string) string

格式化城市行政编码

func FormatDate

func FormatDate(time time.Time, style string) string

func FormatLanguage

func FormatLanguage(s string) string

归纳成统一的语言代码 zh/en/hant

func FromDate

func FromDate(date string) (int, error)

日期字符串转成时间戳

func FromUnixTime

func FromUnixTime(timestamp int) string

时间戳转日期时间

func GenerateNonce

func GenerateNonce(size int) []byte

func GenerateStringNonce

func GenerateStringNonce(size int) string

生成的字符串长度是size的2倍

func GetAge

func GetAge(fromDate string) (int, error)

生日计算年龄 Date format: 2006-01-02

func GetConstellation

func GetConstellation(date string) int

返回星座(1-12)

func GetConstellationMD

func GetConstellationMD(month, day int) int

func GetDayStart

func GetDayStart(d time.Time) time.Time

获取某一天的0点时间

func GetHourStart

func GetHourStart(t time.Time) time.Time

func GetMonthEnd

func GetMonthEnd(d time.Time) time.Time

月初0点

func GetMonthRange

func GetMonthRange(now time.Time) (int, int)

获取(本月1号, 下个月1号)时间戳

func GetMonthStart

func GetMonthStart(d time.Time) time.Time

月初0点

func GetWeekEnd

func GetWeekEnd(t time.Time) time.Time

func GetWeekStart

func GetWeekStart(t time.Time) time.Time

周1零点

func HourIn

func HourIn(fromHour int, endHour int) bool

func InInt32s

func InInt32s(src int32, array []int32) bool

func InInt64s

func InInt64s(src int64, array []int64) bool

func InInts

func InInts(src int, array []int) bool

func InStrings

func InStrings(src string, array []string) bool

func Int32sToInts

func Int32sToInts(src []int32) []int

func Int64sRemove

func Int64sRemove(array []int64, d int64) []int64

func Int64sToSet

func Int64sToSet(a []int64) map[int64]struct{}

数组转集合

func IntsRemove

func IntsRemove(array []int, d int) []int

func IntsToInt32s

func IntsToInt32s(src []int) []int32

func IsAlnum

func IsAlnum(s string) bool

返回true, 如果字符串是字母加数字

func IsDigit

func IsDigit(s string) bool

返回true, 如果字符串由全数字组成

func IsInSameHour

func IsInSameHour(t1 time.Time, t2 time.Time) bool

func IsInSameWeek

func IsInSameWeek(t1 time.Time, t2 time.Time) bool

func IsZh

func IsZh(lang string) bool

是中国语言

func JoinInt64s

func JoinInt64s(il []int64) string

func JoinInts

func JoinInts(il []int) string

func JoinStrings

func JoinStrings(sl []string) string

func JsonDecode

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

func JsonEncode

func JsonEncode(v interface{}) ([]byte, error)

json.Marshal和json.Unmarshal处理int64有bug

func JsonString

func JsonString(v interface{}) string

func Md5String

func Md5String(data []byte) string

func Monday

func Monday(t time.Time) string

周一ymd

func Month

func Month(t time.Time) string

本月ym

func MustJsonDecode

func MustJsonDecode(data []byte, v interface{})

func MustJsonEncode

func MustJsonEncode(v interface{}) []byte

func NormalizePhoneNumber

func NormalizePhoneNumber(number string) (string, error)

手机号归一化

func PhoneToCC

func PhoneToCC(phone_number string) string

手机号转地区代码

func Raise

func Raise(err error)

func RandDigitCode

func RandDigitCode(l int) string

func SampleInt64

func SampleInt64(src []int64, n int) []int64

随机采样n条数据

func Sha1Digest

func Sha1Digest(data []byte) []byte

func Sha1String

func Sha1String(data []byte) string

func ShuffleInt64

func ShuffleInt64(a []int64)

func SubtractInt64s

func SubtractInt64s(a, b []int64) []int64

集合: 求差集 A-B

func ToDate

func ToDate(timestamp int) string

时间戳转日期 2019-07-17

func ToE164

func ToE164(phone_number string) string

转化成ITU E.164格式, +CC MMMMMMMM

func ToIntYMD

func ToIntYMD(time time.Time) int

func ToInts

func ToInts(s string) []int

func ToJson

func ToJson(v interface{}) string

func ToYMD

func ToYMD(timestamp int) string

时间戳转日期 20190717, 负数表示今天或今天之前的相对秒数

func ToYMDHIS

func ToYMDHIS(timestamp int) string

时间戳转日期时间 20190717150405, 负数表示今天或今天之前的相对秒数

func Today

func Today() int

func TrimPhoneCC

func TrimPhoneCC(phone_number string, ccs ...string) string

去除国家代码

func TruncateString

func TruncateString(s string, n int) string

截取字符串

func ValidPhoneNumber

func ValidPhoneNumber(s string) bool

func VerifyAdCode

func VerifyAdCode(code string) bool

粗略检测行政区划编码格式(比如河南: 410000)

Types

type AndroidVersion

type AndroidVersion struct {
	Major int
	Minor int
	Patch int
}

1.0.0

func ParseAndroidVersion

func ParseAndroidVersion(v string) *AndroidVersion

type AppleVersion

type AppleVersion struct {
	Major int
	Minor int
	Patch int
	Build int
}

1.0.0-35

func ParseAppleVersion

func ParseAppleVersion(v string) *AppleVersion

Directories

Path Synopsis
cmd
redis 实现分布式互斥锁
redis 实现分布式互斥锁
生成全局唯一ID
生成全局唯一ID

Jump to

Keyboard shortcuts

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