utils

package
v0.0.0-...-29e02a0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2021-01-05 12:33:08

  • @LastEditors: moo

  • @LastEditTime: 2021-01-06 22:06:26

  • @Description:

  • @Author: moo

  • @Email: moo@163.com

  • @Date: 2021-01-04 23:22:43

  • @LastEditTime: 2021-01-04 23:27:28

  • @LastEditors: moo

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2021-01-06 14:22:20

  • @LastEditors: moo

  • @LastEditTime: 2021-05-28 15:16:07

* @Author: Miles * @Date: 2020-05-25 19:43:36 * @Last Modified by: Miles * @Last Modified time: 2020-05-25 21:10:32

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2021-01-11 13:56:53

  • @LastEditors: moo

  • @LastEditTime: 2021-01-11 15:50:00

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2021-01-09 14:03:49

  • @LastEditors: moo

  • @LastEditTime: 2021-05-19 17:51:09

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2021-01-19 10:29:02

  • @LastEditors: moo

  • @LastEditTime: 2021-01-28 20:43:30

    https://github.com/spaolacci/murmur3

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2021-01-03 18:05:41

  • @LastEditors: moo

  • @LastEditTime: 2021-01-30 15:39:44

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-12-29 16:32:55

  • @LastEditors: moo

  • @LastEditTime: 2021-01-04 15:31:14

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-12-26 17:58:06

  • @LastEditors: moo

  • @LastEditTime: 2020-12-26 17:59:48

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-12-26 17:58:06

  • @LastEditors: moo

  • @LastEditTime: 2020-12-26 17:59:58

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-12-26 17:58:06

  • @LastEditors: moo

  • @LastEditTime: 2021-03-26 16:05:47

stringutil 包含有用于处理字符串的工具函数。

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-10-26 18:35:32

  • @LastEditors: moo

  • @LastEditTime: 2020-12-29 16:45:07

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-12-26 17:58:06

  • @LastEditors: moo

  • @LastEditTime: 2020-12-26 18:18:33

  • @Name:

  • @Descripttion:

  • @Warning:

  • @version:

  • @Author: moo

  • @Date: 2020-12-29 15:03:43

  • @LastEditors: moo

  • @LastEditTime: 2020-12-29 18:59:26

Index

Constants

View Source
const (
	TextBlack = iota + 30
	TextRed
	TextGreen
	TextYellow
	TextBlue
	TextMagenta
	TextCyan
	TextWhite
)
View Source
const (
	TIME_LAYOUT      string = "2006-01-02 15:04:05"
	TIME_DATE_LAYOUT string = "2006-01-02"
)
View Source
const (
	BIG_M = 0xc6a4a7935bd1e995
	BIG_R = 47
	SEED  = 0x1234ABCD
)
View Source
const SECRET = "taoshihan"

Variables

This section is empty.

Functions

func Bd09ToGcj02

func Bd09ToGcj02(lat float64, lon float64) []float64

*

  • 百度 == 》 高德/腾讯
  • @param lat
  • @param lon

func Bd09ToGps84

func Bd09ToGps84(lat float64, lon float64) []float64

*

  • 百度 == 》 84
  • @param lat
  • @param lon
  • @return

func Black

func Black(msg string) string

func Blue

func Blue(msg string) string

func BubbleSort

func BubbleSort(arr *[]int)

冒泡排序 比较相邻元素,较大的往右移

func CheckEmailPassword

func CheckEmailPassword(server string, email string, password string) bool

验证邮箱密码

func ConvertToStr

func ConvertToStr(src string, srcCode string, tagCode string) string

任意编码转特定编码

func CreateRandInt

func CreateRandInt(min int, max int) int

生成随机数

func CurrLocation

func CurrLocation() *time.Location

func Cyan

func Cyan(msg string) string

func DateStrToLastTime

func DateStrToLastTime(s string) time.Time

func DateStrToTime

func DateStrToTime(s string) time.Time

func DateStrToZeroTime

func DateStrToZeroTime(s string) time.Time

func DateToStr

func DateToStr(t time.Time) string

func DetermineEncoding

func DetermineEncoding(html string) (encoding.Encoding, string)

func DifferentArrayUint

func DifferentArrayUint(a []uint, b []uint) []uint

!!!该函数会改变a

func DuplicateArray

func DuplicateArray(a []interface{}) (ret []interface{})

func DuplicateArrayStr

func DuplicateArrayStr(arr []string) []string

func DuplicateArrayUint

func DuplicateArrayUint(v []uint) (ret []uint)

为了性能需要尽可能的减小拷贝,最悲观的情况每个元素只移动一次。 该函数会改变原先的 切片内容次序

func EarthDistance

func EarthDistance(lat1, lng1, lat2, lng2 float64) float64

func EmailSend

func EmailSend(mailConn MailSetting, email string, title string, body string) (err error)

func Encoding

func Encoding(html string, ct string) string

转换编码

func FileGetContent

func FileGetContent(file string) string

获取文件内容,可以打包到二进制

func FilterHtml

func FilterHtml(s string) string

func FilteredSQLInject

func FilteredSQLInject(to_match_str string) bool

正则过滤sql注入的方法 参数 : 要匹配的语句

func GapDays

func GapDays(t1, t2 time.Time) int

计算日期相差多少天 返回值day>0, t1晚于t2; day<0, t1早于t2

func GapMonth

func GapMonth(t1, t2 time.Time) (month int)

func Gcj02ToBd09

func Gcj02ToBd09(lat float64, lon float64) []float64

*

  • 高德/腾讯 == 》 百度
  • @param lat
  • @param lon

func Gcj02ToGps84

func Gcj02ToGps84(lat float64, lon float64) []float64

*

  • 高德/腾讯 ==》 84
  • @param lon * @param lat * @return *

func GenPwdHash

func GenPwdHash(userPassword string) (string, error)

GenePwdHash 给密码就行加密操作

func GeneSalt

func GeneSalt() string

func Get

func Get(url string) string

func GetCateory15Min

func GetCateory15Min(bgndt time.Time, enddt time.Time) []string

* TODO *

func GetCateoryDay

func GetCateoryDay(bgndt time.Time, enddt time.Time) []string

func GetCateoryDay1

func GetCateoryDay1(bgndt time.Time, enddt time.Time) []string

func GetCateoryHour

func GetCateoryHour(bgndt time.Time, enddt time.Time) []string

func GetCateoryMonth

func GetCateoryMonth(bgndt time.Time, enddt time.Time) []string

func GetCateoryMonth1

func GetCateoryMonth1(bgndt time.Time, enddt time.Time) []string

func GetCookie

func GetCookie(r *http.Request, name string) string

func GetCrossSectionArea

func GetCrossSectionArea(rr float64, hh float64) float64

func GetDecoder

func GetDecoder() *mime.WordDecoder

func GetExternalIp

func GetExternalIp() string

func GetFirstDateOfMonth

func GetFirstDateOfMonth(d time.Time) time.Time

获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。

func GetFolders

func GetFolders(server string, email string, password string, folder string) map[string]int

获取邮件夹

func GetLastDateOfMonth

func GetLastDateOfMonth(d time.Time) time.Time

获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。

func GetLastTime

func GetLastTime(d time.Time) time.Time

func GetLocalIP

func GetLocalIP() []string

func GetMailNum

func GetMailNum(server string, email string, password string) map[string]int

获取邮件总数

func GetServerIP

func GetServerIP() (net.IP, error)

func GetUrlArg

func GetUrlArg(r *http.Request, name string) string

获取URL的GET参数

func GetVCodeBase64

func GetVCodeBase64() (string, string, error)

func GetZeroTime

func GetZeroTime(d time.Time) time.Time

获取某一天的0点时间

func Gps84ToBd09

func Gps84ToBd09(lat float64, lon float64) []float64

*

  • 84 == 》 百度
  • @param lat
  • @param lon
  • @return

func Gps84ToGcj02

func Gps84ToGcj02(lat float64, lon float64) []float64

*

  • 84 ==》 高德/腾讯
  • @param lat
  • @param lon
  • @return

func Green

func Green(msg string) string

func Hash

func Hash(s string) string

func HourDiffer

func HourDiffer(start_time, end_time time.Time) int64

获取两个时间相差多少小时

func InsertionSort

func InsertionSort(arr *[]int)

插入排序 将未排序部分插入到已排序部分的适当位置

func IsDate

func IsDate(s string) bool

func IsEmail

func IsEmail(s string) bool

func IsEnChar

func IsEnChar(s string) bool

func IsFileExist

func IsFileExist(path string) (bool, error)

判断文件文件夹是否存在

func IsHan

func IsHan(s string) bool

func IsIDCard

func IsIDCard(s string) bool

中国身份证

func IsMobile

func IsMobile(s string) bool

func IsNumber

func IsNumber(s string) bool

func JsonEscHTMLStr

func JsonEscHTMLStr(data interface{}) string

func Logger

func Logger() *logrus.Logger

func LoggerToFile

func LoggerToFile() gin.HandlerFunc

func Magenta

func Magenta(msg string) string

func MakeToken

func MakeToken(obj map[string]interface{}) (string, error)

func Md5

func Md5(src string) string

md5加密

func MergeSort

func MergeSort(arr *[]int, left int, right int)

归并排序 合久必分,分久必合,利用临时数组合并两个有序数组

func MinuteDiffer

func MinuteDiffer(start_time, end_time time.Time) int64

获取两个时间相差多少分钟

func MurmurHash64A

func MurmurHash64A(data []byte) (h int64)

func ParseIp

func ParseIp(myip string) *ipdb.CityInfo

func ParseToken

func ParseToken(tokenStr string) map[string]interface{}

func QuickSort

func QuickSort(arr *[]int, left int, right int)

递归

func QuickSort2

func QuickSort2(arr *[]int, left int, right int)

快速排序2 找到一个基准,左边是所有比它小的,右边是比它大的,分别递归左右

func RandFloat

func RandFloat(min, max float64) float64

func RandomContent

func RandomContent(size int) string

func RandomInt

func RandomInt(min int, max int) int

func RandomMobile

func RandomMobile() string

func RandomName

func RandomName() string

func RandomSite

func RandomSite() string

func RandomString

func RandomString(size int) string

func RandomTime

func RandomTime() time.Time

func RandomTitle

func RandomTitle() string

func Red

func Red(msg string) string

func RedirectStderr

func RedirectStderr(f *os.File)

redirectStderr to the file passed in

func Reverse

func Reverse(s string) string

Reverse 将其实参字符串以符文为单位左右反转。

func Reverse2

func Reverse2(s string) string

Reverse2 将其实参字符串以符文为单位左右反转。

func SelectionSort

func SelectionSort(arr *[]int)

选择排序 选择一个最小值,再寻找比它还小的进行交换

func Send

func Send(server string, from string, password string, to []string, subject string, body string) error

func SendSms

func SendSms(mobile string, contentStr string) error

func SetColor

func SetColor(msg string, conf, bg, text int) string

func SetCookie

func SetCookie(name string, value string, w *http.ResponseWriter)

func ShowStringByte

func ShowStringByte(str string)

func StrToInt

func StrToInt(s string) int

string to int

func StrToUint

func StrToUint(s string) uint

func String2Time

func String2Time(in string) (out time.Time, err error)

func StringLen

func StringLen(s string) int

func StringSub

func StringSub(s string, length int) string

func TimeStrToTime

func TimeStrToTime(s string) time.Time

func TimeToStr

func TimeToStr(t time.Time) string

func TrimHtml

func TrimHtml(sHtml string) string

func TrimHtmlDesc

func TrimHtmlDesc(sHtml string, iLen int) string

func TruncFloat

func TruncFloat(f float64, unit float64) float64

uint 代表小数位数,格式位 0.000001 如果是几位就指定为几位

func UnFilterHtml

func UnFilterHtml(s string) string

func Uuid

func Uuid() string

func ValidatePwd

func ValidatePwd(userPassword string, hashed string) bool

ValidatePwd 密码比对

func VerifyVCodeBase64

func VerifyVCodeBase64(id string, val string) bool

func White

func White(msg string) string

func Yellow

func Yellow(msg string) string

Types

type GPSMODE

type GPSMODE int
const (
	GPSMODE_WGS84 GPSMODE = 0 // 国际标准,GPS坐标(Google Earth使用、或者GPS模块)
	GPSMODE_GCJ02 GPSMODE = 1 // 中国坐标偏移标准,Google Map、高德、腾讯使用
	GPSMODE_BD09  GPSMODE = 2 // 百度坐标偏移标准
)

type IndexData

type IndexData struct {
	ViewHtml
	Folders           map[string]int
	Mails             interface{}
	MailPagelist      []*MailItem
	CurrentPage       int
	Fid               string
	NextPage, PrePage string
	NumPages          template.HTML
}

type JsonListResult

type JsonListResult struct {
	JsonResult
	Result interface{} `json:"result"`
}

type JsonResult

type JsonResult struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

type MailItem

type MailItem struct {
	Subject string
	Fid     string
	Id      uint32
	From    string
	To      string
	Body    string
	Date    string
}

func GetFolderMail

func GetFolderMail(server string, email string, password string, folder string, currentPage int, pagesize int) []*MailItem

获取邮件夹邮件

func GetMessage

func GetMessage(server string, email string, password string, folder string, id uint32) *MailItem

type MailPageList

type MailPageList struct {
	MailItems []*MailItem
}

type MailServer

type MailServer struct {
	Server, Email, Password string
}

func GetMailServerFromCookie

func GetMailServerFromCookie(r *http.Request) *MailServer

type MailSetting

type MailSetting struct {
	User string
	Pwd  string
	Host string
	Port int
	Desc string
}

type RspSms

type RspSms struct {
	ReturnStatus  string `xml:"returnstatus"`
	Message       string `xml:"message"`
	RemainPoint   string `xml:"remainpoint"`
	TaskID        string `xml:"taskID"`
	SuccessCounts string `xml:"successCounts"`
}

type SmtpBody

type SmtpBody struct {
	Smtp     string
	From     string
	To       []string
	Password string
	Subject  string
	Body     string
}

type Snowflake

type Snowflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A Snowflake struct holds the basic information needed for a snowflake generator worker

func NewSnowflake

func NewSnowflake(workerid int64) (*Snowflake, error)

NewNode returns a new snowflake worker that can be used to generate snowflake IDs

func (*Snowflake) Generate

func (s *Snowflake) Generate() int64

Generate creates and returns a unique snowflake ID

type ViewData

type ViewData struct {
	Folders  map[string]int
	HtmlBody template.HTML
	MailItem
}

type ViewHtml

type ViewHtml struct {
	Header template.HTML
	Nav    template.HTML
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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