utils

package
v0.0.0-...-ba852ca Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

@Time : 2019/5/14 11:26 @Author : Lukebryan @File : hmacsha256util.go @Software: GoLand

@Time : 2019/5/14 9:30 @Author : Lukebryan @File : httputil.go @Software: GoLand

@Time : 2019/5/8 16:20 @Author : Lukebryan @File : md5.go @Software: GoLand

@Time : 2019/5/14 10:40 @Author : Lukebryan @File : tokenutil.go @Software: GoLand

Index

Constants

This section is empty.

Variables

View Source
var FilePath = FilePathConf{}
View Source
var Producer *nsq.Producer
View Source
var RpcConfig = &RpcConf{}

Functions

func BubbleSort

func BubbleSort(sort []float64, num int) float64

冒泡排序找出数组中最大或者最小的数据 num=1为最大 num=2为最小

func CloneRepo

func CloneRepo(repoDir string, branch string, gitAdd string) bool

Clone项目 repoDir string 项目保存地址(Git本地仓库) branch string 项目分支(Git分支) gitAdd string 项目git地址(Git地址)

func CopyFile

func CopyFile(dstName, srcName string) (written int64, err error)

复制文件 目标文件,源文件

func CreateNumberStr

func CreateNumberStr(figures int, startNumber int) string

创建数字字符串(不足前面补0) CreateNumberStr(4,0) return 0001 CreateNumberStr(5,1) return 00002

func CreateRandNum

func CreateRandNum(figures int, rang int) (numberStr string)

创建多位数长度数字字符串 figures位数 rang随机数范围

func Defer

func Defer(tx *gorm.DB, flag *bool)

func DownLoadFile

func DownLoadFile(u iris.Context, allFileName string, newFileName string) error

文件下载

func ExecCommand

func ExecCommand(commandName string, params []string) bool

执行命令函数 commandName 命名名称,如cat,ls,git等 params 命令参数,如ls -l的-l,git log 的log等

func ExportExcel1

func ExportExcel1(header []string, data interface{})

func GenerateRandomNumber

func GenerateRandomNumber(end int, count int) []int

func GenerateRandomNumber2

func GenerateRandomNumber2(end int, count int) []int

func GentToken

func GentToken(userID string, wechat_id string) string

func GetChineseSize

func GetChineseSize(str string) int

提取字符串中汉字的长度/3

func GetCurrentYear

func GetCurrentYear() string

获取系统当前年份+1

func GetDayString

func GetDayString(time string) string

截取时间字符串中的日期有小尾巴2019-01-04 17:42:29

func GetDayStringNoTail

func GetDayStringNoTail(time string) string

截取时间字符串中的日期没有小尾巴2019-01-04

func GetEnglishOrSymbol

func GetEnglishOrSymbol(str string) int

提取字符串中英汉或符号的长度

func GetEnglishOrSymbolChineseSize

func GetEnglishOrSymbolChineseSize(str string) int

获取提取完后字符串后的长度

func GetFloatToString

func GetFloatToString(f float64) string

Float64转string

func GetMD5String

func GetMD5String(strings string) string

func GetMonthString

func GetMonthString(time string) string

截取时间字符串中的月份有小尾巴2019-01-04 17:42:29

func GetMonthStringNoTail

func GetMonthStringNoTail(time string) string

截取时间字符串中的月份没有小尾巴2019-01-04

func GetNginxTemplate

func GetNginxTemplate(root string, port string, locations []string) (template string)

root:静态文件地址 例如:/home/vue/dist/test port:监听端口 例如:9527

func GetPidByProcessName

func GetPidByProcessName(name string) string

func GetRand

func GetRand(result int, groupExpertNumber int) (ids []int)

func GetSimilarity

func GetSimilarity(str1, str2 string) float64

Levenshtein算法

func GetTimeNow

func GetTimeNow() *time.Time

获取系统当前时间

func GetTimeStringNow

func GetTimeStringNow() string

获取当前时间 string 有小尾巴

func GetTimeStringNowNoTail

func GetTimeStringNowNoTail() string

获取当前时间 string 没有小尾巴

func GetTimeUnix

func GetTimeUnix() string

获取当前时间戳

func GetYearString

func GetYearString(time string) string

截取时间字符串中的年份有小尾巴2019-01-04 17:42:29

func GetYearStringNoTail

func GetYearStringNoTail(time string) string

截取时间字符串中的年份没有小尾巴2019-01-04

func HmacSha256Encode

func HmacSha256Encode(strings string, secret string) string

func InitProducer

func InitProducer(str string)

初始化生产者

func Krand

func Krand(size int, kind int) []byte

func Md5ByByte

func Md5ByByte(bytes []byte) string

func MkDirs

func MkDirs(dir string) bool

创建文件夹

func NewServer

func NewServer(ServerAddress string, ConsulAddress []string, BasePath string) *server.Server

func PathExists

func PathExists(path string) (bool, error)

判断文件夹是否存在

func PostFormRequest

func PostFormRequest(path string, datas map[string]interface{}, headers map[string]string) (resultBody string, err error)

form表单post请求

func PostRequest

func PostRequest(r *http.Request, path string) (resultBody string, err error)

原样请求

func Publish

func Publish(topic string, message string) error

发布消息

func ReadExcel

func ReadExcel(path string, fileName string) [][]string

读取Excel

func RemoveRep

func RemoveRep(s []uint) []uint

func Round

func Round(x float64) int

float64转int四舍五入

func SplitCommandAndExec

func SplitCommandAndExec(text string) (success bool)

切割命令行,执行命令 text 命令行

func StringFormatTime

func StringFormatTime(times string) time.Time

string格式转time

func SubTime

func SubTime(str string) string

处理时间格式

func Substr

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

截取字符串 start 起点下标 length 需要截取的长度

func Substr2

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

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

func TimeFormatString

func TimeFormatString(time time.Time) string

time格式转string

func TrimHtml

func TrimHtml(src string) string

func TrimHtml2

func TrimHtml2(src string) string

去除字符串中的样式

func UniqueId

func UniqueId() string

生成Guid字串

func UpFile

func UpFile(u iris.Context) (string, string)

文件上传 当前时间戳作为文件名

func UploadFile

func UploadFile(u iris.Context) string

文件上传 当前时间戳作为文件名

func UploadFile2

func UploadFile2(u iris.Context) string

func UploadFiles

func UploadFiles(u iris.Context) string

文件上传 原文件名

func WriteFile

func WriteFile(filePath string, fileName string, fileContent string) bool

filePath:文件路径 例如:/usr/local/test fileName:文件名 例如:test.conf fileContent:文件内容 例如:Hello World!

Types

type Excel

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

Excel:excel struct

func (*Excel) Export

func (el *Excel) Export(inFile, outDir string) (outFile string, err error)

type FilePathConf

type FilePathConf struct {
	FileSavePath string
	Ip           string
	SpaceJPort   string
	SysUrl       string
}

type JsonStruct

type JsonStruct struct{}

读取json配置文件

func NewJsonStruct

func NewJsonStruct() *JsonStruct

func (*JsonStruct) Load

func (jst *JsonStruct) Load(filename string, v interface{})

type RpcConf

type RpcConf struct {
	Addr            string `json:"Addr"`
	ConsulAddr      string `json:"ConsulAddr"`
	BasePath        string `json:"BasePath"`
	NsqAddr         string `json:"NsqAddr"`
	UserBasePath    string `json:"UserBasePath"`
	UserServicePath string `json:"UserServicePath"`
}

type Set

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New() *Set

New: 返回一个Set实例

func (*Set) Add

func (s *Set) Add(item interface{})

Add: 增加一个元素

func (*Set) Clear

func (s *Set) Clear()

Clear: 清除Set

func (*Set) Has

func (s *Set) Has(item interface{}) bool

Has: 是否存在指定的元素

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

Empty: Set是否是空

func (*Set) Len

func (s *Set) Len() int

Len: 返回元素个数

func (*Set) List

func (s *Set) List() []interface{}

List: 获取Map转化成的list

func (*Set) Remove

func (s *Set) Remove(item interface{})

Remove: 移除一个元素

Jump to

Keyboard shortcuts

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