helper

package
v0.0.0-...-c5e6d41 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2014 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RsaPublicKey = []byte(`
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZsfv1qscqYdy4vY+P4e3cAtmv
ppXQcRvrF1cB4drkv0haU24Y7m5qYtT52Kr539RdbKKdLAM6s20lWy7+5C0Dgacd
wYWd/7PeCELyEipZJL07Vro7Ate8Bfjya+wltGK9+XNUIHiumUKULW4KDx21+1NL
AUeJ6PeW+DAkmJWF6QIDAQAB
-----END PUBLIC KEY-----
`)

	RsaPrivateKey = []byte(`
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDZsfv1qscqYdy4vY+P4e3cAtmvppXQcRvrF1cB4drkv0haU24Y
7m5qYtT52Kr539RdbKKdLAM6s20lWy7+5C0DgacdwYWd/7PeCELyEipZJL07Vro7
Ate8Bfjya+wltGK9+XNUIHiumUKULW4KDx21+1NLAUeJ6PeW+DAkmJWF6QIDAQAB
AoGBAJlNxenTQj6OfCl9FMR2jlMJjtMrtQT9InQEE7m3m7bLHeC+MCJOhmNVBjaM
ZpthDORdxIZ6oCuOf6Z2+Dl35lntGFh5J7S34UP2BWzF1IyyQfySCNexGNHKT1G1
XKQtHmtc2gWWthEg+S6ciIyw2IGrrP2Rke81vYHExPrexf0hAkEA9Izb0MiYsMCB
/jemLJB0Lb3Y/B8xjGjQFFBQT7bmwBVjvZWZVpnMnXi9sWGdgUpxsCuAIROXjZ40
IRZ2C9EouwJBAOPjPvV8Sgw4vaseOqlJvSq/C/pIFx6RVznDGlc8bRg7SgTPpjHG
4G+M3mVgpCX1a/EU1mB+fhiJ2LAZ/pTtY6sCQGaW9NwIWu3DRIVGCSMm0mYh/3X9
DAcwLSJoctiODQ1Fq9rreDE5QfpJnaJdJfsIJNtX1F+L3YceeBXtW0Ynz2MCQBI8
9KP274Is5FkWkUFNKnuKUK4WKOuEXEO+LpR+vIhs7k6WQ8nGDd4/mujoJBr5mkrw
DPwqA3N5TMNDQVGv8gMCQQCaKGJgWYgvo3/milFfImbp+m7/Y3vCptarldXrYQWO
AQjxwc71ZGBFDITYvdgJM1MTqc8xQek1FXn1vfpy2c6O
-----END RSA PRIVATE KEY-----
`)

	AesKey       = "jjsdj#$827gfgh38dakljzmknghsj#2k" //32位
	AesPublicKey = "akljzmknm.ahkjkl"                 //16位
)

Functions

func AesDecrypt

func AesDecrypt(ciphertext string, privateKey string, publicKey string) (string, error)

AES解密

func AesEncrypt

func AesEncrypt(content string, privateKey string, publicKey string) (string, error)

AES加密

func AtPages

func AtPages(content string) ([]string, string)

获取文本中 @urls 的网址集合 ###AtPages函数的作用是提取@后面的url网址,并不是提取图片,请注意!

func AtPagesGetImages

func AtPagesGetImages(content string) ([]string, string)

func AtUsers

func AtUsers(content string) (usrs []string)

获取文本中 @user 中的用户名集合

func Base64Encoding

func Base64Encoding(s string) string

func C2C

func C2C(fromstr string, tostr string, str string) string

轉換邏輯,翻譯過程處理函數

func CheckEmail

func CheckEmail(email string) (b bool)

func CheckPassword

func CheckPassword(password string) (b bool)

func CheckUsername

func CheckUsername(username string) (b bool)

func CompareDiff

func CompareDiff(fg1, fg2 string) int

Pha Compare

func ContainsSets

func ContainsSets(values []string, ivalue string) bool

func Convzh

func Convzh(str string, lang string) []byte

func DelLostImages

func DelLostImages(oldz string, newz string)

func DifferenceSets

func DifferenceSets(a []string, b []string) []string

差集

func Encrypt_hash

func Encrypt_hash(password string, salt []byte) string

func Exist

func Exist(filename string) bool

func Filehash

func Filehash(path_or string, file_or *os.File) (string, error)

func Filehash_block

func Filehash_block(path string, block int64) string

func Filehash_number

func Filehash_number(path string) (int, error)

func FixedpathByNumber

func FixedpathByNumber(n int, layer int) string

func FixedpathByString

func FixedpathByString(s string, layer int) string

func Fixurl

func Fixurl(current_url, url string) string

func GetBanner

func GetBanner(content string) (string, error)

func GetBannerThumbnail

func GetBannerThumbnail(content string) (string, error)

func GetFile

func GetFile(file_url string, file_path string, useragent string, referer string) error

func GetImagePha

func GetImagePha(path string) (string, error)

PHA算法 获取图像指纹

func GetImages

func GetImages(content string) (imgs []string, num int)

返回 图片url列表集合

func GetPage

func GetPage(url string) (string, error)

返回获得的网页内容

func GetSensitiveInfoRemovedEmail

func GetSensitiveInfoRemovedEmail(email string) string

func GetThumbnails

func GetThumbnails(content string) (thumbnails string, thumbnailslarge string, thumbnailsmedium string, thumbnailssmall string, err error)

func Gravatar

func Gravatar(email string, height int) string

根据用户邮箱显示Gravatar头像

func Hotness

func Hotness(ups int64, downs int64, createTime time.Time) float64

func Hotness_Score

func Hotness_Score(ups int64, downs int64) int64

reddit 排序算法

func Html2str

func Html2str(html string) string

func Htmlquote

func Htmlquote(text string) string

func Htmlunquote

func Htmlunquote(text string) string

func IntersectionSets

func IntersectionSets(fora []string, forb []string) []string

交集

func IsLocal

func IsLocal(path string) bool

func IsSpider

func IsSpider(userAgent string) bool

检查是否为搜索引擎爬虫

func Local2url

func Local2url(path string) string

func MD5

func MD5(s string) string

对字符串进行md5哈希, 返回32位小写md5结果

func MD5(s string) string {
	h := md5.New()
	io.WriteString(h, s)
	return fmt.Sprintf("%x", h.Sum(nil))
}

func MD5_16

func MD5_16(s string) string

对字符串进行md5哈希, 返回16位小写md5结果

func MakeThumbnails

func MakeThumbnails(localpath string) (thumbnails string, thumbnailslarge string, thumbnailsmedium string, thumbnailssmall string, err error)

func Markdown

func Markdown(md string) template.HTML

func Markdown2Text

func Markdown2Text(md string) string

func Metric

func Metric(n int64) string

返回数字带数量级单位 千对k 百万对M 京对G

func MoveFile

func MoveFile(frompath string, topath string) error

func Nrand

func Nrand(n int64) float64

标准正态分布随机整数,n为随机个数,从0开始

func PHA

func PHA(m image.Image) string

func Pages

func Pages(results_count int, page int, pagesize int) (pages int, pageout int, beginnum int, endnum int, offset int)

分页计算函数

func Pagesbar

func Pagesbar(url string, keyword string, results_max int, pages int, page int, beginnum int, endnum int, style int) (output template.HTML)

func PhaCompare

func PhaCompare(path1 string, path2 string) (int, error)

指纹比较

func PingFile

func PingFile(url string) bool

func PostFile

func PostFile(filepath string, actionurl string, fieldname string) (*http.Response, error)

func Qhot

func Qhot(Qviews int64, Qanswers int64, Qscore int64, Ascores int64, Created time.Time, ReplyTime time.Time) float64

func Qhot_AScore

func Qhot_AScore(ups int64, downs int64) int64

func Qhot_QScore

func Qhot_QScore(ups int64, downs int64) int64

func Qhot_Vote

func Qhot_Vote(ups int64, downs int64) int64

func RangeRand

func RangeRand(n int) int

生成规定范围内的整数 设置起始数字范围,0开始,n截止

func ReceivingPackets

func ReceivingPackets(decrypt bool, hash string, status string, content []byte, aesPublicKey string, rsaPublicKey []byte, rsaPrivateKey []byte) ([]byte, error)

func Resample

func Resample(m image.Image, r image.Rectangle, w, h int) image.Image

重新取样返回一个重采样本的图像切片r的副本。 返回的图像具有宽度w和高度h。 Resample returns a resampled copy of the image slice r of m. The returned image has width w and height h.

func Resize

func Resize(m image.Image, r image.Rectangle, w, h int) image.Image

调整传回的图像片的R米的缩放副本。 返回的图像具有宽度w和高度h。 Resize returns a scaled copy of the image slice r of m. The returned image has width w and height h.

func Rex

func Rex(text string, iregexp string) (b bool)

func Round

func Round(val float64, prec int) float64

round() 函数对浮点数进行四舍五入 语法 round(val,prec) 参数 val 规定要舍入的数字。 prec 规定小数点后的位数

func RsaDecrypt

func RsaDecrypt(ciphertext []byte, privateKey []byte) ([]byte, error)

RSA解密

func RsaEncrypt

func RsaEncrypt(origData []byte, publicKey []byte) ([]byte, error)

RSA加密

func S2T

func S2T(str string) string

func SHA1

func SHA1(s string) string

对字符串进行sha1哈希, 返回42位小写sha1结果

func SendMail

func SendMail(user, password, host, to, subject, body, mailtype string) error

* * user : example@example.com login smtp server user * password: xxxxx login smtp server password * host: smtp.example.com:port smtp.163.com:25 * to: example@example.com;example1@163.com;example2@sina.com.cn;... * subject:The subject of mail * body: The content of mail * mailtype: mail type html or text

func SendingPackets

func SendingPackets(encrypt bool, status string, actionurl string, content string, aesKey string, aesPublicKey string, rsaPublicKey []byte) (*http.Response, error)

发送报文 是否加密 HTTP状态 动作URL 数据内容 RSA公匙

func SetSuffix

func SetSuffix(content string, str string) string

设置后缀

func SmcTimeSince

func SmcTimeSince(timeAt time.Time) string

func Str2Ans

func Str2Ans(str string) int64

func Str2html

func Str2html(raw string) template.HTML

func StrLen

func StrLen(str string) int64

func StrOne

func StrOne(str string, where int64) string

func StrPos

func StrPos(str string, sep string) int64

func StringNewRand

func StringNewRand(len int) string

func StringNewUUID

func StringNewUUID() string

NewUUID generates a new UUID based on version 4.

func StringToUTF16

func StringToUTF16(s string) []uint16

字符串转换来unit16

func Substr

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

截取字符

func SymmetricDifferenceSets

func SymmetricDifferenceSets(fora []string, forb []string) []string

对称差=并集-交集 即是 并集和交集的差集就是对称差

func T2S

func T2S(str string) string

func Tags

func Tags(content string, str string) []string

分割tags

func ThisDate

func ThisDate() time.Time

获取今天的开始点

func ThisHour

func ThisHour() time.Time

获取这个小时的开始点

func ThisMonth

func ThisMonth() time.Time

获取这月的开始点

func ThisWeek

func ThisWeek() time.Time

获取这周的开始点

func ThisYear

func ThisYear() time.Time

获取今年的开始点

func Thumbnail

func Thumbnail(mode string, input_file string, output_file string, output_size string, output_align string, background string) error

#gravity可用值有九个,分别是:

西北方 NorthWest:左上角为坐标原点,x轴从左到右,y轴从上到下,也是默认值。 北方 North:上部中间位置为坐标原点,x轴从左到右,y轴从上到下。 东北方 NorthEast:右上角位置为坐标原点,x轴从右到左,y轴从上到下。 西方 West:左边缘中间位置为坐标原点,x轴从左到右,y轴从上到下。 中央 Center:正中间位置为坐标原点,x轴从左到右,y轴从上到下。 东方 East:右边缘的中间位置为坐标原点,x轴从右到左,y轴从上到下。 西南方 SouthWest:左下角为坐标原点,x轴从左到右,y轴从下到上。 南方 South:下边缘的中间为坐标原点,x轴从左到右,y轴从下到上。 东南方 SouthEast:右下角坐标原点,x轴从右到左,y轴从下到上。

func TimeSince

func TimeSince(created time.Time) string

* 微博时间格式化显示

  • @param timestamp,标准时间戳

func UnionSets

func UnionSets(fora []string, forb []string) []string

并集

func Url2local

func Url2local(path string) string

func Validate_hash

func Validate_hash(hashed string, input_password string) bool

func VerifyUserfile

func VerifyUserfile(path string, usr string) bool

func Watermark

func Watermark(watermark_file string, input_file string, output_file string, output_align string) error

func WriteFile

func WriteFile(path string, filename string, content string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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