lea

package
Version: v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: GPL-2.0, GPL-2.0-or-later Imports: 21 Imported by: 0

README

The leanote util package

Documentation

Overview

contains two cryptographic functions for both storing and comparing passwords.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearDir

func ClearDir(dir string) bool

清空dir下所有的文件和文件夹 RemoveAll会清空本文件夹, 所以还要创建之

func CompareHash

func CompareHash(digest []byte, password string) bool

CompareHash compares bcrypt password with a plaintext one. Returns true if passwords match and false if they do not.

func ComparePwd

func ComparePwd(rawPwd, dbPwd string) bool

对比密码是否一致 因为之前密码是用md5加密的, 所以通过密码长度来判断 rawPwd 原始, 用户输入的密码

func CopyDir

func CopyDir(source string, dest string) (err error)

func CopyFile

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

func DeleteFile

func DeleteFile(path string) bool

func Digest2

func Digest2(str string) string

func Digest3

func Digest3(str string) string

3位数的转换, 为了用bson.id -> 3位数

func FixFilename

func FixFilename(filename string) string

将名称的特殊字符去掉

func FixUrlTime

func FixUrlTime(t time.Time) time.Time

修复传过来的时间, 如果比今天大, 则设为现在

func GenPwd

func GenPwd(rawPwd string) string

加密

func GenerateHash

func GenerateHash(password string) ([]byte, error)

GenerateHash generates bcrypt hash from plaintext password

func GetFileStrContent

func GetFileStrContent(path string) string

获得文件str内容

func GetFilename

func GetFilename(path string) string

func GetFilesize

func GetFilesize(path string) int64

file size length in bytes

func GetRandomFilePath

func GetRandomFilePath(userId, uuid string) string

得到用户的随机文件路径 3位/userId/2位

func InArray

func InArray(arr []string, str string) bool

func InitEmail

func InitEmail()

func InitVd

func InitVd()

func IsDirExists

func IsDirExists(path string) bool

func IsEmail

func IsEmail(email string) bool

是否是email

func IsFileExist

func IsFileExist(filename string) bool

func IsGoodPwd

func IsGoodPwd(pwd string) (bool, string)

是否是合格的密码

func IsObjectId

func IsObjectId(id string) (ok bool)

是否是ObjectId

func IsUsername

func IsUsername(username string) bool

是否只包含数字, 字母 -, _

func IsValidTime

func IsValidTime(t time.Time) bool

是否是合法的时间 不是, 0001-01-01T00:00:00Z, 且比今天小

func L

func L(i interface{})

为test用

func LJ

func LJ(i interface{})

func ListDir

func ListDir(dir string) []string

list dir's all file, return filenames

func Log

func Log(msg string, i ...interface{})

func LogJ

func LogJ(i interface{})

func LogW

func LogW(msg string, i ...interface{})

func Logf

func Logf(msg string, i ...interface{})

func Md5

func Md5(s string) string

md5

func MkdirAll

func MkdirAll(dir string) bool

func NewGuid

func NewGuid() string

Guid

func NewGuidWith

func NewGuidWith(str string) string

后面加个str生成之, 更有保障, 确保唯一

func PutFileStrContent

func PutFileStrContent(path, content string) bool

写入string内容

func RandomPwd

func RandomPwd(num int) string

随机密码 num 几位

func ReplaceAll

func ReplaceAll(oldStr, pattern, newStr string) string

截取含html的字符串

<div>

abcdef
<p>xxxxxxxxxxx</p>
<img src="" />
<div>
	abcdfef
	<p>aksdfjsld
	dfsadf
	--------------- 这里截断
	</p>
	<p>xxxxxxxxxxxxxxx</p>
	abcdef
</div>

</div> 那么只要在最后的html中添加</p></div></div>补全结束即可 思路: 1. 找到截断的位置 2. 去掉成对的标签 3. 去掉不要结束的标签 4. 补全标签

func SendEmailOld

func SendEmailOld(to, subject, body string) bool

func SendToLeanoteOld

func SendToLeanoteOld(subject, title, body string)

func SplitFilename

func SplitFilename(filename string) (baseName, ext string)

分离文件名与扩展名(包含.)

func SubStringHTML

func SubStringHTML(param string, length int, end string) string

获取摘要, HTML

func SubStringHTMLToRaw

func SubStringHTMLToRaw(param string, length int) string

获取纯文本

func Substr

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

func Substring

func Substring(str string, start int) string

func SubstringByte

func SubstringByte(str string, start int) string

以byte来截取

func ToLocalTime

func ToLocalTime(t time.Time) time.Time

url传过来的时间没有时区信息, 转到本地时间

func TransToGif

func TransToGif(path string, maxWidth uint, afterDelete bool) (ok bool, transPath string)

func TransferExt

func TransferExt(path string, toExt string) string

转换文件的格式 toExt包含.

func Vd

func Vd(name, value string) (ok bool, msg string)

func Vds

func Vds(m map[string]string) (ok bool, msg string)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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