gosupport

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 27 Imported by: 7

README

gosupport

go support, go functions
本库用途: go常用方法、算法等的封装,提供基于go原生语法打造的类库
本库代码无第三方库依赖,仅依赖go内置函数、go语法

常用算法、工具是日积月累的,持续打磨,完善,坚持、加油!!!

Language Go Reference Goproxy.cn

Requirements

gosupport library requires Go version >=1.14

Install下载依赖

go get -u github.com/jellycheng/gosupport
或者
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/jellycheng/gosupport

直接获取master分支代码:
    go get -u github.com/jellycheng/gosupport@master
    

Documentation

https://pkg.go.dev/github.com/jellycheng/gosupport

Usage调用示例

package main

import (
	"fmt"
	"github.com/jellycheng/gosupport"
    "github.com/jellycheng/gosupport/utils"
)

func main() {
    // 求和
	total := gosupport.IntSum(10, 30, 51)
	fmt.Println(total) //91
    
    sCode := utils.NewMintCompress().Compress(1680) // 数值生成对应的压缩码
	fmt.Println(sCode) //Yt
	// md5加密
	fmt.Println(gosupport.Md5V1("hello world")) //5eb63bbbe01eeed093cb22bb8f5acdc3

    // 时间戳转日期格式: 2021-05-24 16:59:04
    stime := gosupport.Time()
    fmt.Println(gosupport.Timestamp2DateTime(int(stime), 1))
    // 2021年05月24日 17时03分05秒
    fmt.Println(gosupport.DateT("Y年m月d日 H时i分s秒", *gosupport.TimeNowPtr()))

}

Documentation

Index

Constants

View Source
const (
	V1 byte
	V2
	V3
	V4
	V5
	V6
	V7
	V8
	V9
	V10
)

版本常量

View Source
const (
	// 空字符串
	Empty = ""

	// 签名方式
	SignTypeMD5        = "MD5"
	SignTypeHmacSHA256 = "HMAC-SHA256"
	SignTypeRSA        = "RSA"

	PrivateFileMode = 0600
)
View Source
const (
	CharsetStr1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	CharsetStr2 = "0123456789"
	// 去掉了i、j、l、o、u、v、z、I、J、L、O、U、V、Z、0、1、2字符
	CharsetStr3 = "abcdefghkmnpqrstwxyABCDEFGHKMNPQRSTWXY3456789"
)

字符及字符串相关常量

View Source
const (
	TIME_FORMAT       = "2006-01-02 15:04:05"
	TimeFormat        = "2006-01-02 15:04:05"
	DateFormat        = "2006-01-02"
	TFormat           = "15:04:05"
	DTNoSecondsFormat = "2006-01-02 15:04"
)

日期时间相关常量

View Source
const (
	PHP_EOL = "\n"
	GO_EOL  = "\n"
)
View Source
const (
	FgBlack   uint8 = iota + 30 // 黑色
	FgRed                       // 红色
	FgGreen                     //绿色
	FgYellow                    //黄色
	FgBlue                      //蓝色
	FgFuchsia                   // 紫红色
	FgCyan                      // 青蓝色
	FgWhite                     // 白色
)

前景色即文字颜色

View Source
const (
	BgBlack uint8 = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgFuchsia
	BgCyan
	BgWhite
)

背景色

View Source
const (
	// 是否包含html标签
	HTMLRegexStr = `<[/]?([a-zA-Z]+).*?>`
	// 纯字母
	LetterRegexStr = "^[a-zA-Z]+$"
	// 纯数字
	NumberRegexStr = "^[0-9]+$"
	// 字母 + 数字
	LetterNumericRegexStr = "^[a-zA-Z0-9]+$"
	// 正负浮点数、正负整数
	NumericRegexStr = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
	// 以 #;开头的字符就算是注释行
	CommentLineRegexStr = "^\\s*[#;]+"

	WwVerify = "^WW_verify_([0-9a-zA-Z]{16}).txt$"
	MpVerify = "^MP_verify_([0-9a-zA-Z]{16}).txt$"
)

Variables

This section is empty.

Functions

func AlreadyTimeStr

func AlreadyTimeStr(t2 time.Time, timezone ...*time.Location) string

已运行时长: d天h小时m分钟s秒

func Camel2Case

func Camel2Case(name string) string

驼峰转下划线,如:ImgKeyXyz 转 Img_Key_Xyz

func Case2Camel

func Case2Camel(name string) string

下划线写法转为驼峰写法,如:img_key 转 ImgKey

func CheckErr

func CheckErr(err error)

func ClearColorCode added in v1.0.4

func ClearColorCode(str string) string

ClearColorCode 提取颜色样式中的文本内容,示例:fmt.Println(ClearColorCode(ToYellow("goods")))

func CreateAnchor

func CreateAnchor(str string) string

对特殊字符使用中划线替换 CreateAnchor("abc?你好?中=国123abc") 返回 abc-你好-中-国123abc CreateAnchor("你好中国123abc")返回 你好中国123abc CreateAnchor("你好中国 123 abc") 返回 你好中国-123-abc CreateAnchor("how 你好 中国123a!bc#de") 返回 how-你好-中国123a-bc-de

func CreateSuperiorDir

func CreateSuperiorDir(path string) bool

创建上级目录,存在或者创建成功返回true、创建失败返回false

func Date

func Date(format string, timestamp int64, timezone ...*time.Location) string

时间戳转指定的时间格式:gosupport.Date(gosupport.TimeFormat, unixTime时间戳)

func DateT

func DateT(format string, t time.Time) string

Y年,4位 y年,后2位 m月份,有前导0 n月份,无加前导0 d日,有前导0 j日,无加前导0 H 24小时制,有前导0 G 24小时制,无前导0 h 12小时制,有前导0 g 12小时制,无前导0 i 分钟,有前导0 ii 分钟,无前导0 s 秒,有前导0 ss 秒,无前导0 类似php的写法 Y-m-d H:i:s

func DayStartEndTime

func DayStartEndTime(t time.Time, timezone ...*time.Location) (time.Time, time.Time)

某天的开始时间和结束时间

func DebugPrintReflect

func DebugPrintReflect(x interface{})

调用示例:gosupport.DebugPrintReflect(time.Hour)

func DefaultGOPATH

func DefaultGOPATH() string

获取默认gopath目录

func Die

func Die(status int)

func Echo

func Echo(args ...interface{})

输出,类似php的echo()函数

func EchoF

func EchoF(args interface{})

func EmptyStruct

func EmptyStruct() struct{}

返回空结构体

func EmptyStructSlice

func EmptyStructSlice() []struct{}

返回空结构体切片,用于json序列化时返回空数组[]

func EqualsIgnoreCase

func EqualsIgnoreCase(a, b string) bool

忽略大小写比较字符串

func ExecCmd

func ExecCmd(cmdName string, args ...string) (string, string, error)

当前目录作为工作目录来执行命令,调用示例: okContent,errContent, err := gosupport.ExecCmd("ls", "-l")

func ExecCmdBytes

func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error)

当前目录作为工作目录来执行命令

func ExecCmdDir

func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error)

func ExecCmdDirBytes

func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error)

func Exit

func Exit(status int)

func ExtractContent4Tag

func ExtractContent4Tag(str, tag string) []string

从str中提取tag内的内容

func Fen2yuan

func Fen2yuan(price int64, isTrimZero bool) string

分转元 price := 1909 s1 := gosupport.Fen2yuan(int64(price), true)

func Fen2yuan4int added in v1.0.4

func Fen2yuan4int(price int, isTrimZero bool) string

分转元

func FileExists

func FileExists(path string) bool

判断文件/文件夹是否存在,true存在,false不存在

func FileExt

func FileExt(f string) string

获取文件扩展名

func FileGetContents

func FileGetContents(filename string) (string, error)

读取文件内容

func FileMTime

func FileMTime(file string) (int64, error)

获取文件修改时间

func FilePutContents

func FilePutContents(filename string, content string, perm ...os.FileMode) (int, error)

写内容

func FileSize

func FileSize(file string) (int64, error)

获取文件大小

func Float64Rank

func Float64Rank(data []float64, order string, isRepeatOrder bool) map[float64]int

排名算法 示例: ret := gosupport.Float64Rank([]float64{-1,0,2.9,3,2.9}, "desc", false)

func Float64Toint

func Float64Toint(fNum float64) (int, error)

float64类型转int,丢弃小数部分

func Float64Toint64

func Float64Toint64(fNum float64) (int64, error)

float64类型转int64,丢弃小数部分

func FromatUUIDString

func FromatUUIDString(s string) string

返回 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

func GenerateUserAgent

func GenerateUserAgent(appname string, ext ...string) string

调用示例:gosupport.GenerateUserAgent("user-service", "1.0.0")

func GetCallFuncName

func GetCallFuncName() string

获取调用我的函数名,即获取当前方法名,返回 包名.方法名、包名.结构体名.方法名

func GetCallInfo

func GetCallInfo() map[string]string

func GetDefaultTimezone added in v1.0.3

func GetDefaultTimezone() *time.Location

获取默认时区

func GetEnv

func GetEnv(env, defaultValue string) string

获取环境变量值

func GetExcelLetter

func GetExcelLetter(column int) string

column列从1开始

func GetGoVersion

func GetGoVersion() string

获取当前go版本

func GetGwHostEnvName

func GetGwHostEnvName(gwName string) string

获取网关env配置名,即配置key

func GetLocalIPV1 added in v1.0.1

func GetLocalIPV1() []string

获取本机ip,一般取第0个单元作为本机ip,示例:ip := gosupport.GetLocalIPV1()[0]

func GetMpVerifyVal added in v1.0.4

func GetMpVerifyVal(str string) string

GetMpVerifyVal 提取内容,例如 MP_verify_d4RP2dwJOG3lDBub.txt 提取出 d4RP2dwJOG3lDBub

func GetRandString

func GetRandString(length int) string

获取指定长度的随机字符串

func GetRandStringWithCharset

func GetRandStringWithCharset(length int, charset string) string

获取指定charset字符集下指定长度length的随机字符串

func GetShanghaiTimezone

func GetShanghaiTimezone() *time.Location

获取上海时区

func GetStructTagContent

func GetStructTagContent(i interface{}, fieldNname string, tagName string) (string, bool)

获取结构体某字段的tag值

func GetSummary

func GetSummary(s string, length int) string

去掉空格后,截取指定长度的字数,并打上...点字符

func GetWwVerifyVal added in v1.0.4

func GetWwVerifyVal(str string) string

GetWwVerifyVal 提取内容,例如 WW_verify_P3fNz9uLSkgAlsnI.txt 提取出P3fNz9uLSkgAlsnI

func GitCheckout added in v1.0.1

func GitCheckout(codeRootDir string) (string, error)

切换到指定目录checkout

func GitPull added in v1.0.1

func GitPull(codeRootDir string) (string, error)

切换到指定目录拉取最新代码

func InitStruct4DefaultTag

func InitStruct4DefaultTag(bean interface{})

通过结构体的default标签设置结构体默认值,入参为指针类型

func Int64Filter

func Int64Filter(data []int64, callBack func(i int64) bool) []int64

func Int64InSlice

func Int64InSlice(a int64, list []int64) bool

示例:fmt.Println(gosupport.Int64InSlice(9, []int64{5, 6, 9}))

func Int64s

func Int64s(a []int64)

升序

func IntFilter

func IntFilter(data []int, callBack func(i int) bool) []int

func IntInSlice

func IntInSlice(a int, list []int) bool

func IntSliceToStringSlice

func IntSliceToStringSlice(arr []int) ([]string, bool)

将[]int转为[]string, s,_ := gosupport.IntSliceToStringSlice([]int{123, 78919})

func IntSum

func IntSum(nums ...int) int

求和

func InterfacetoString

func InterfacetoString(data interface{}, sep string) string

s := gosupport.InterfacetoString([]interface{}{10, 200}, ",")

func IsAccountName

func IsAccountName(str string) bool

判断是否普通账号名,必须以字母开头,可由字母、数字、下划线组成

func IsBlank added in v1.0.1

func IsBlank(str string) bool

是否空串 或者 全是 空格

func IsDir

func IsDir(path string) bool

判断是否为文件夹

func IsDirWriteable

func IsDirWriteable(dir string) error

func IsEmpty

func IsEmpty(val interface{}) bool

判断是否为空或零

func IsEmptyV2 added in v1.0.1

func IsEmptyV2(str string) bool

是否是空字符串

func IsFile

func IsFile(path string) bool

判断文件是否存在

func IsFloatNumber

func IsFloatNumber(str string) bool

字符串是否为浮点数字符串

func IsMail

func IsMail(mail string) bool

是否邮箱

func IsMobile

func IsMobile(str string) bool

是否手机号,11位数字

func IsNotBlank added in v1.0.1

func IsNotBlank(str string) bool

func IsNotEmptyV2 added in v1.0.1

func IsNotEmptyV2(str string) bool

是否不是空字符串

func IsNumber

func IsNumber(str string) bool

字符串是否为正整数数字字符串

func IsPhone

func IsPhone(str string) bool

是否座机

func IsStrMaper added in v1.0.4

func IsStrMaper(handler interface{}) bool

func IsUrl

func IsUrl(str string) bool

是否链接

func IsZeroCode

func IsZeroCode(code interface{}) bool

判断code值是否为0,c := '0'认为是int32类型对应ascii值为48

func JsonUnmarshal added in v1.0.2

func JsonUnmarshal(str string, obj interface{}) error

func KeysOfMap

func KeysOfMap(m map[string]string) []string

对map的key进行排序,返回排序后的key切片

func KeysOfMapV2

func KeysOfMapV2(m map[string]interface{}) []string

func Lcfirst

func Lcfirst(str string) string

首字母小写

func LoadJson

func LoadJson(jsonFile string, t interface{}) error

调用示例: data := make(map[string]interface{})

if err :=LoadJson("./cjs.json", &data);err!=nil{
	fmt.Println("解析失败", err.Error())
} else {
	fmt.Println(data)
}

func Map2XML

func Map2XML(kvs map[string]string) (text []byte, err error)

func Map2XMLV2

func Map2XMLV2(params map[string]string, rootName ...string) string

func MbStrlen

func MbStrlen(str string) int

获取字符串长度,类似php的mb_strlen()函数

func Md5

func Md5(str string) string

md5加密

func Md5File

func Md5File(path string) (string, error)

获取文件的md5值

func Md5V1

func Md5V1(str string) string

md5加密

func Md5V2

func Md5V2(str string) string

使用md5加密方式2

func Md5V3

func Md5V3(str string) string

func Md5V4

func Md5V4(s string) string

func Md5V5

func Md5V5(bt []byte) string

调用示例: gosupport.Md5V5([]byte{'h','e', 'l','l','o',' ', 'w','o','r','l','d'})

func MergeStringMap

func MergeStringMap(list ...map[string]string) map[string]string

func MyAssert

func MyAssert(guard bool, str string)

func NewRedisInfo

func NewRedisInfo() redisinfo

func Nl2br

func Nl2br(str string) string

换行符转html换行标签

func PrintErr

func PrintErr(err error)

func RandStr4Byte

func RandStr4Byte(n int, way int) string

n 获取随机字符个数 way 选择参与随机字符串的方式

func RegexpVerify

func RegexpVerify(val string, reg string) bool

正则表达式验证字符串

func RemoveDian00

func RemoveDian00(priceStr string) string

调用示例:gosupport.RemoveDian00("18.00") 返回 18

func RemoveRepeatByFloat32

func RemoveRepeatByFloat32(data []float32) []float32

float32切片内容去重

func RemoveRepeatByFloat64

func RemoveRepeatByFloat64(data []float64) []float64

float64切片内容去重

func RemoveRepeatByInt

func RemoveRepeatByInt(data []int) []int

int切片内容去重

func RemoveRepeatByInt16

func RemoveRepeatByInt16(data []int16) []int16

int16切片内容去重

func RemoveRepeatByInt32

func RemoveRepeatByInt32(data []int32) []int32

int32切片内容去重

func RemoveRepeatByInt64

func RemoveRepeatByInt64(data []int64) []int64

int64切片内容去重

func RemoveRepeatByInt8

func RemoveRepeatByInt8(data []int8) []int8

int8切片内容去重

func RemoveRepeatByString

func RemoveRepeatByString(data []string) []string

字符串切片内容去重

func RemoveRepeatContent

func RemoveRepeatContent(data interface{}) (interface{}, error)

使用示例 abc,_ := RemoveRepeatContent([]float64{9.9, 18.9, 22, 9.9, 22, 33})

if v,ok := abc.([]float64);ok{
	fmt.Println(v[2]) //22
}

func ReplaceStar4Phone

func ReplaceStar4Phone(phone string) string

隐藏手机号中间4位

func ReplaceStar4String

func ReplaceStar4String(str string, start int, maxLen int) string

从开始位置替换为*号 start开始位置-从0开始计算,maxLen最多打星个数

func ReverseInt64s

func ReverseInt64s(a []int64)

倒序

func ShuffleStr added in v1.0.1

func ShuffleStr(s []string)

返回随机打乱后的切片,洗牌算法,切片引用传递

func ShuffleStr4Copy added in v1.0.1

func ShuffleStr4Copy(s []string) []string

func Sleep

func Sleep(t int64)

func SliceErrorf

func SliceErrorf(format string, args ...interface{}) error

切片错误内容格式化

func SliceJointoString

func SliceJointoString(data interface{}, sep string, isRemove bool) (string, error)

把切片内容拼接成字符串

func Str2Int

func Str2Int(str string) int

func StrInSlice

func StrInSlice(a string, list []string) bool

list切片中是否有a字符串

func StringFilter

func StringFilter(data []string, callBack func(s string) bool) []string

过滤字符串切片内容 示例:

 s1 := []string{"hello", "", "yes", "0","yes"}
	s2 := gosupport.StringFilter(s1, func(s string) bool {
		if s == "" || s == "0" {
			return false
		}
		return true
	})

func StringNumber2Int64Slice

func StringNumber2Int64Slice(data []string) []int64

func StringNumber2IntSlice

func StringNumber2IntSlice(data []string) []int

func StringSliceToIntSlice

func StringSliceToIntSlice(arr []string) ([]int, bool)

将[]string转为[]int, s,_ := gosupport.StringSliceToIntSlice([]string{"123", "78919"})

func StripTags

func StripTags(s string, tags ...string) string

去除html标签

func Strlen

func Strlen(str string) int

获取字符串长度,类似php的strlen()函数

func Strrev

func Strrev(str string) string

反转字符串

func Strtotime

func Strtotime(format, strtime string, timezone ...*time.Location) (int64, error)

按日期格式+时间转时间戳 unixTime,_ := gosupport.Strtotime(gosupport.TimeFormat,"2021-01-02 02:36:43")

func SubDays

func SubDays(t1, t2 time.Time) (day int)

计算日期相差多少天:t1-t2

func SubTimeStr

func SubTimeStr(t2 time.Time, timezone ...*time.Location) string

1分钟以内显示为:刚刚 1小时以内显示为:N分钟前 当天以内显示为:今天 N点N分(如:今天 22:33) 昨天时间显示为:昨天 N点N分(如:昨天 10:15) 在今年显示为:N月N日 N点N分(如:02月03日 09:33) 今年以前显示为:N年N月N日 N点N分(如:2020年09月18日 15:59)

func Substr

func Substr(str string, start int, end int) string

截取字符串 start 起点下标 end 终点下标(不包括)

func Time

func Time(timezone ...*time.Location) int64

func Time2TimeStr

func Time2TimeStr(t *time.Time) string

入参指针类型,返回示例:2019-11-28T01:13:36Z

func Time2TimeStr2

func Time2TimeStr2(t time.Time) string

入参非指针类型,返回示例:2019-11-28T01:13:36Z

func TimeFormat2Date

func TimeFormat2Date(t time.Time) string

调用示例:gosupport.TimeFormat2Date(time.Date(2019, 07, 01, 0, 0, 0, 0, time.UTC)) 返回格式为 年/月/日,如:2019/07/01 、 2019/11/28

func TimeFormat2DateWay

func TimeFormat2DateWay(t time.Time, way int) string

func TimeNow added in v1.0.4

func TimeNow(timezone ...*time.Location) int64

TimeNow 获取时间戳

func TimeNow2Day

func TimeNow2Day(timezone ...*time.Location) int

当前时间转日格式,返回示例:28

func TimeNow2Format

func TimeNow2Format(format string, timezone ...*time.Location) string

当前时间转指定日期格式,s:= gosupport.TimeNow2Format("20060102") fmt.Println(gosupport.TimeNow2Format("2006.01.02 15:04:05"))

func TimeNow2Month

func TimeNow2Month(timezone ...*time.Location) int

当前时间转月格式,返回示例:11

func TimeNow2String

func TimeNow2String(timezone ...*time.Location) string

当前时间转年月日格式,返回示例:20191128

func TimeNow2YMD

func TimeNow2YMD(timezone ...*time.Location) (int, int, int)

当前时间返回年月日

func TimeNow2YearMonth

func TimeNow2YearMonth(timezone ...*time.Location) int

当前时间转年月格式,返回示例:201911

func TimeNowMillisecond added in v1.0.4

func TimeNowMillisecond(timezone ...*time.Location) int64

TimeNowMillisecond 获取毫秒

func TimeNowPtr

func TimeNowPtr() *time.Time

返回当前时间结构体指针类型

func TimePtr2Str

func TimePtr2Str(t *time.Time) string

入参指针类型,返回格式示例:2019-11-28 09:22:30

func TimePtr2Str2

func TimePtr2Str2(t time.Time) string

func TimeStr2Time

func TimeStr2Time(t string) time.Time

func TimeToSlice

func TimeToSlice(t time.Time) []int

func Timestamp2DateTime

func Timestamp2DateTime(timestamp int, way int, timezone ...*time.Location) string

时间戳转日期时间格式,调用示例: gosupport.Timestamp2DateTime(1569152644, 7)

func Timestamp2DateTime4int64

func Timestamp2DateTime4int64(timestamp int64, way int, timezone ...*time.Location) string

时间戳转日期时间格式,调用示例: gosupport.Timestamp2DateTime4int64(1622039023, 1)

func Timestamp2Time added in v1.0.3

func Timestamp2Time(timestamp int64, timezone ...*time.Location) time.Time

时间戳转time.Time对象

func ToBool

func ToBool(s string) bool

func ToBoolOr

func ToBoolOr(s string, defaultValue bool) bool

func ToCamelCase

func ToCamelCase(str string) string

转为小驼峰格式: 空格的首字母转大写,如:hello world_abc厉害 转 helloWorld_abc厉害

func ToColor added in v1.0.4

func ToColor(code string, msg string) string

func ToGreen

func ToGreen(str string) string

func ToJson

func ToJson(v interface{}) string

转成json字符串

func ToRed

func ToRed(str string) string

ToRed 返回红色样式,用于在终端打印红色字,调用示例:fmt.Println(gosupport.ToRed("hello world"))

func ToSnakeCase

func ToSnakeCase(str string) string

转为snake格式: 全部转小写,空格转_,如:Abc_Xy z_eLsW中国 转 abc_xy_z_elsw中国

func ToStr

func ToStr(value interface{}, args ...int) (s string)

任意值转字符串

func ToYellow

func ToYellow(str string) string

func TodayStartEndTime

func TodayStartEndTime(timezone ...*time.Location) (time.Time, time.Time)

今天开始时间和结束时间

func Typeof

func Typeof(v interface{}) string

获取变量or值的类型

func Ucfirst

func Ucfirst(str string) string

首字母大写

func Uniq

func Uniq(salt string, isFormat bool) string

func UrlDeal

func UrlDeal(reqUrl string, otherGetParam string) string

url中追加参数 调用示例:gosupport.UrlDeal("nfangbian.com/fangan/index/?xyz=1#ab", "a=1&b=2")

func Usleep

func Usleep(t int64)

func Void

func Void()

空函数,什么也不做

func WriteContentType added in v1.0.4

func WriteContentType(w http.ResponseWriter, value []string)

func XML2Map

func XML2Map(text []byte) (result map[string]string, err error)

func XmlUnmarshal added in v1.0.4

func XmlUnmarshal(str string, obj interface{}) error

Types

type ArgInt

type ArgInt []int

func (ArgInt) Get

func (a ArgInt) Get(i int, args ...int) (r int)

示例:var abc gosupport.ArgInt = []int{101, 11,12,33}

fmt.Println(abc.Get(1, 10)) //11

i表取切片第i个值,小于0则取args的第1个值

type AssertTime

type AssertTime struct {
	// 支持的日期格式
	TimeFormats []string
}

func NewAssertTime

func NewAssertTime() *AssertTime

func (*AssertTime) ParseAssertFormat

func (m *AssertTime) ParseAssertFormat(str string, location *time.Location) (t time.Time, err error)

分析并断言的日期时间则返回,否则返回错误

type Author

type Author struct {
	Name  string //作者
	Email string //作者邮箱
}

作者结构体 调用示例: var Authors []gosupport.Author //存批量作者 Authors = append(Authors, gosupport.Author{Name: "张三", Email: "admin@xxx.com"}) Authors = append(Authors, gosupport.Author{Name: "李四", Email: "lisi@xxx.com"})

for _,v:=range Authors{
	fmt.Println(v.String())
}

func (Author) String

func (a Author) String() string

返回作者格式

type CDATA

type CDATA string

func (CDATA) MarshalXML

func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type ConverterFunc

type ConverterFunc func(string) string

type CorsConfig

type CorsConfig struct {
	//是否开启跨域,true是,false否
	IsOpenCors bool
	//允许的源,默认*,赋值给 Access-Control-Allow-Origin
	AllowOrigins string
	//允许的请求方式,默认*,如GET、POST,赋值给Access-Control-Allow-Methods
	AllowMethods []string
	//允许的请求头,赋值给 Access-Control-Allow-Headers
	AllowHeaders []string
	//值为 true、false,赋值给Access-Control-Allow-Credentials
	AllowCredentials bool
	//赋值给 Access-Control-Max-Age
	MaxAge time.Duration
}

func DefaultCorsConfig

func DefaultCorsConfig() CorsConfig

corsConfig := gosupport.DefaultCorsConfig()

func (*CorsConfig) AddAllowHeaders

func (c *CorsConfig) AddAllowHeaders(headers ...string)

设置允许的请求头

func (*CorsConfig) AddAllowMethods

func (c *CorsConfig) AddAllowMethods(methods ...string)

设置允许的请求方式

func (*CorsConfig) GenerateHttpHeaders

func (c *CorsConfig) GenerateHttpHeaders() http.Header

生成http类型头,类型:type Header map[string][]string

func (*CorsConfig) GetAllowOrigins

func (c *CorsConfig) GetAllowOrigins() string

获取允许的源

func (*CorsConfig) SetAllowOrigins

func (c *CorsConfig) SetAllowOrigins(origin string)

设置允许的源

type DataManage

type DataManage struct {
	DataMutex *sync.RWMutex
	Data      map[string]interface{}
}

func NewGlobalCfgSingleton

func NewGlobalCfgSingleton() *DataManage

func NewGlobalEnvSingleton

func NewGlobalEnvSingleton() *DataManage

func (*DataManage) Get

func (dm *DataManage) Get(key string) (value interface{}, exists bool)

func (*DataManage) GetBool

func (dm *DataManage) GetBool(key string) (b bool)

func (*DataManage) GetData

func (dm *DataManage) GetData() map[string]interface{}

func (*DataManage) GetFloat64

func (dm *DataManage) GetFloat64(key string) (f64 float64)

func (*DataManage) GetInt

func (dm *DataManage) GetInt(key string) (i int)

func (*DataManage) GetInt64

func (dm *DataManage) GetInt64(key string) (i64 int64)

func (*DataManage) GetString

func (dm *DataManage) GetString(key string) (s string)

func (*DataManage) MustGet

func (dm *DataManage) MustGet(key string) interface{}

func (*DataManage) Set

func (dm *DataManage) Set(key string, value interface{})

type H added in v1.0.4

type H map[string]interface{}

func (H) MarshalXML added in v1.0.4

func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML allows type H to be used with xml.Marshal.

func (H) ToJson added in v1.0.4

func (h H) ToJson() string

func (H) ToJsonByte added in v1.0.4

func (h H) ToJsonByte() ([]byte, error)

func (H) WriteContentType added in v1.0.4

func (h H) WriteContentType(w http.ResponseWriter, value []string) H

func (H) WriteJson added in v1.0.4

func (h H) WriteJson(w http.ResponseWriter) H

func (H) WriteXml added in v1.0.4

func (h H) WriteXml(w http.ResponseWriter) H

type IdentifyInterface

type IdentifyInterface interface {
}

标识性接口

type Int64Slice

type Int64Slice []int64

myInt64 := []int64{9, 8,10,7} sort.Sort(gosupport.Int64Slice(myInt64)) // 升序,或者 gosupport.Int64s(myInt64) 或者 gosupport.Int64Slice(myInt64).Sort() fmt.Println(myInt64) //[7 8 9 10]

func (Int64Slice) Len

func (x Int64Slice) Len() int

func (Int64Slice) Less

func (x Int64Slice) Less(i, j int) bool

func (Int64Slice) Sort

func (x Int64Slice) Sort()

func (Int64Slice) Swap

func (x Int64Slice) Swap(i, j int)

type Metadata added in v1.0.4

type Metadata map[string]string

func (Metadata) Clone added in v1.0.4

func (m Metadata) Clone() StrMaper

func (Metadata) Del added in v1.0.4

func (m Metadata) Del(key string)

func (Metadata) Get added in v1.0.4

func (m Metadata) Get(key string) (value string, ok bool)

func (Metadata) Set added in v1.0.4

func (m Metadata) Set(key string, value string)

type MyMapStringInt

type MyMapStringInt struct {
	Key   string
	Value int
}

type MyMapStringIntList

type MyMapStringIntList []MyMapStringInt

func MapSortByValue

func MapSortByValue(m map[string]int, so string) MyMapStringIntList

对map的int值排序, ret := gosupport.MapSortByValue(map[string]int{"abc":123, "xyz":4}, "desc")

func (MyMapStringIntList) Len

func (p MyMapStringIntList) Len() int

func (MyMapStringIntList) Less

func (p MyMapStringIntList) Less(i, j int) bool

func (MyMapStringIntList) Swap

func (p MyMapStringIntList) Swap(i, j int)

type MySliceInt64

type MySliceInt64 struct {
	// contains filtered or unexported fields
}

func NewMySliceInt64

func NewMySliceInt64() *MySliceInt64

obj := NewMySliceInt64() obj.Push(9)

func (*MySliceInt64) GetData

func (m *MySliceInt64) GetData() []int64

func (*MySliceInt64) Pop

func (m *MySliceInt64) Pop() (int64, bool)

从栈中获取数据

func (*MySliceInt64) Push

func (m *MySliceInt64) Push(value int64)

向栈中添加数据

func (*MySliceInt64) RemoveRepeatData

func (m *MySliceInt64) RemoveRepeatData() []int64

func (*MySliceInt64) SetData

func (m *MySliceInt64) SetData(d []int64)

type PIDFile

type PIDFile struct {
	// contains filtered or unexported fields
}

对pid文件的操作

func NewPIDFile

func NewPIDFile(pidfile string) *PIDFile

调用示例: pidFile := "/data/www/go-community-service/go-community-service.pid" pidFileObj := gosupport.NewPIDFile(pidFile) err := pidFileObj.CreatePidFile(os.Getpid())

if err !=nil {
	fmt.Println(err.Error())
}

pid2,_ := pidFileObj.GetPid() fmt.Println("pidfile=", pidFile, "pid=", pid2) pidFileObj.Remove()

func (PIDFile) CreatePidFile

func (f PIDFile) CreatePidFile(pid int) error

创建pid文件,存在pid文件则写失败, pid=os.Getpid()

func (PIDFile) GetPid

func (f PIDFile) GetPid() (int, error)

func (PIDFile) Remove

func (f PIDFile) Remove() error

移除pid文件

type RedisGroupManage

type RedisGroupManage struct {
	// contains filtered or unexported fields
}

redis组管理

func NewRedisGroupManage

func NewRedisGroupManage() *RedisGroupManage

func (RedisGroupManage) Get

func (this RedisGroupManage) Get(groupName string) (redisinfo, error)

func (RedisGroupManage) GetPrefix

func (this RedisGroupManage) GetPrefix(groupName string) string

获取当前redis组的配置key前缀

func (*RedisGroupManage) Set

func (this *RedisGroupManage) Set(groupName string, cfg redisinfo)

func (*RedisGroupManage) SetMap

func (this *RedisGroupManage) SetMap(groupName string, info map[string]interface{})

type Scheme

type Scheme string

协议相关常量

const (
	HTTP  Scheme = "http"
	HTTPS Scheme = "https"
	FTP   Scheme = "ftp"
)

type SeqString added in v1.0.2

type SeqString string

func (SeqString) GetUidMod4Seq added in v1.0.2

func (m SeqString) GetUidMod4Seq() int64

func (SeqString) GetUidMod4Seq2Str added in v1.0.2

func (m SeqString) GetUidMod4Seq2Str() string

type Sequence added in v1.0.2

type Sequence struct {
	// contains filtered or unexported fields
}

Sequence seq字符串格式:%s%s%06s%03s 分别是 前缀+(6位年月日*100000+5位时间差(当前时间戳-今天凌晨时间戳))+ (步长%999999=前导补零的6位串) +(用户ID%128)

func NewSequence added in v1.0.2

func NewSequence() *Sequence

func (Sequence) GetSeq added in v1.0.2

func (m Sequence) GetSeq(uidModVal ...int64) string

func (*Sequence) GetUidMod added in v1.0.2

func (m *Sequence) GetUidMod() int64

func (*Sequence) SetPrefix added in v1.0.2

func (m *Sequence) SetPrefix(prefixVal string) *Sequence

func (*Sequence) SetStepSize added in v1.0.2

func (m *Sequence) SetStepSize(stepSizeVal int64) *Sequence

func (*Sequence) SetUid added in v1.0.2

func (m *Sequence) SetUid(uidVal int64) *Sequence

type SliceError

type SliceError struct {
	Msg string
}

切片错误结构体

func (*SliceError) Error

func (e *SliceError) Error() string

type StrMaper added in v1.0.4

type StrMaper interface {
	// 获取值
	Get(key string) (string, bool)
	// 设置值
	Set(key, value string)
	// 删除
	Del(key string)
	// 克隆
	Clone() StrMaper
}

type StrTo

type StrTo string

使用示例: gosupport.StrTo("123456789").MustUint64()

func (StrTo) Float32

func (f StrTo) Float32() (float32, error)

func (StrTo) Float64

func (f StrTo) Float64() (float64, error)

func (StrTo) Int

func (f StrTo) Int() (int, error)

func (StrTo) Int64

func (f StrTo) Int64() (int64, error)

func (StrTo) IntV0

func (f StrTo) IntV0() (int, error)

func (StrTo) MustFloat32

func (f StrTo) MustFloat32() float32

func (StrTo) MustFloat64

func (f StrTo) MustFloat64() float64

func (StrTo) MustInt

func (f StrTo) MustInt() int

func (StrTo) MustInt64

func (f StrTo) MustInt64() int64

func (StrTo) MustUint64

func (f StrTo) MustUint64() uint64

func (StrTo) MustUint8

func (f StrTo) MustUint8() uint8

func (StrTo) String

func (f StrTo) String() string

func (StrTo) Uint64

func (f StrTo) Uint64() (uint64, error)

func (StrTo) Uint8

func (f StrTo) Uint8() (uint8, error)

type WrapError added in v1.0.4

type WrapError struct {
	Error error
}

func NewWrapError added in v1.0.4

func NewWrapError() WrapError

func (*WrapError) AddError added in v1.0.4

func (me *WrapError) AddError(e error) error

AddError 追加db错误信息对象

Directories

Path Synopsis
library

Jump to

Keyboard shortcuts

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