Documentation ¶
Index ¶
- Constants
- func BinFileToStruct(filepath string, to interface{}) error
- func BytesToFile(data []byte, filepath string) error
- func BytesToImage(imgbytes []byte, filepath string) error
- func BytesToStruct(data []byte, to interface{}) error
- func CryptPassword(password, salt string) string
- func CurrentDir() string
- func CurrentUser() string
- func GenRandomString(length int, specialChar string) string
- func GetMD5(text string) string
- func GetNowTime() string
- func GetNowTime2() string
- func GetNowTimeStamp() int64
- func ImageToBytes(filepath string) ([]byte, error)
- func ImageType(imgbytes []byte) string
- func InStringSlice(s []string, x string) (bool, int)
- func IsExist(name string) bool
- func IsNumber(input string) bool
- func JSONBytesToFile(data []byte, filepath string) error
- func JSONBytesToStruct(data []byte, structObj interface{}) error
- func JSONFileToBytes(filepath string) ([]byte, error)
- func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte
- func NewRSAFile(pubKeyFilename, priKeyFilename string, keyLength int) error
- func NewRSAString(keyLength int) (string, string, error)
- func QRCodeParse(fi io.Reader) (string, error)
- func ReadRSAKeyPair(pubKeyFilename, priKeyFilename string) ([]byte, []byte, error)
- func SendMessage(notice Notice) (bool, error)
- func StructToBinFile(structObj interface{}, filepath string) error
- func StructToBytes(structObj interface{}) ([]byte, error)
- func TwoStepAuthGenNumber(t *TOTP) (string, int64, error)
- func UserHome() (string, error)
- func WriteRSAKeyPair(publicKeyWriter, privateKeyWriter io.Writer, keyLength int) error
- type BoltDB
- type DingTalkClient
- type DingTalkMessage
- type EmailClient
- type EmailMessage
- type GoAES
- type GoRSA
- type HLog
- func (hl *HLog) GetLogger() (*HLogger, error)
- func (hl *HLog) SetDateFormat(format string)
- func (hl *HLog) SetLevel(level string)
- func (hl *HLog) SetLogType(logType string)
- func (hl *HLog) SetMaxAge(day time.Duration)
- func (hl *HLog) SetRotationTime(day time.Duration)
- func (hl *HLog) SetSeparateLevelLog(yes bool)
- type HLogger
- func (logger *HLogger) Debug(commonFields map[string]interface{}, message string)
- func (logger *HLogger) Error(commonFields map[string]interface{}, message string)
- func (logger *HLogger) Fatal(commonFields map[string]interface{}, message string)
- func (logger *HLogger) Info(commonFields map[string]interface{}, message string)
- func (logger *HLogger) Panic(commonFields map[string]interface{}, message string)
- func (logger *HLogger) Warn(commonFields map[string]interface{}, message string)
- type JWToken
- type Notice
- type TOTP
Constants ¶
const ( // Oneday 一天 Oneday = 24 * time.Hour )
const ( // RSAAlgorithmSign RSA签名算法 RSAAlgorithmSign = crypto.SHA256 )
Variables ¶
This section is empty.
Functions ¶
func BinFileToStruct ¶
BinFileToStruct 二级制文件反序列化为结构体,结构体必须要和转换前的结构一致 filepath 二进制文件路径 to 结构体对象 结构必须和序列化前的一样
func BytesToImage ¶
BytesToImage []byte生成图片 imgbytes 图片[]byte数组 filepath 文件路径名称
func BytesToStruct ¶
BytesToStruct []byte转换为结构体,必须事先知道结构体的结构,而且必须一样 data 转换后的字节数组 to 结构体对象 结构必须和序列化前的一样
func GenRandomString ¶
GenRandomString 生成随机字符串 length 生成长度 specialChar 是否生成特殊字符
func ImageToBytes ¶
ImageToBytes 图片转换为字节数组 filepath 图片的路径
func InStringSlice ¶
InStringSlice 元素是否在一个string类型的slice里面
func JSONBytesToFile ¶
JSONBytesToFile json []byte 写入文件
func JSONBytesToStruct ¶
JSONBytesToStruct json []byte 转换为 struct
func JSONFileToBytes ¶
JSONFileToBytes 从json文件中转换为[]byte
func MarshalPKCS8PrivateKey ¶
func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte
MarshalPKCS8PrivateKey 私钥解析
func NewRSAFile ¶
NewRSAFile 生成密钥对文件 pubKeyFilename: 公钥文件名 priKeyFilename: 私钥文件名 kekeyLength: 密钥长度
func NewRSAString ¶
NewRSAString 生成密钥对字符串 keyLength 密钥的长度
func ReadRSAKeyPair ¶
ReadRSAKeyPair 读取RSA密钥对 pubKeyFilename: 公钥文件名称 priKeyFilename: 私钥文件名
func StructToBinFile ¶
StructToBinFile 结构体序列化成二级制文件 structObj 结构体对象 filepath 文件路径
func StructToBytes ¶
StructToBytes 结构体转换为[]byte structObj 结构体对象
func TwoStepAuthGenNumber ¶
TwoStepAuthGenNumber 根据提供的 secret 来生成6位数字 返回 6位数字、剩余时间
Types ¶
type DingTalkClient ¶
type DingTalkClient struct { RobotURL string Message *DingTalkMessage }
DingTalkClient 通过钉钉机器人发送消息
func (*DingTalkClient) SendMessage ¶
func (d *DingTalkClient) SendMessage() (bool, error)
SendMessage 通过钉钉机器人发送消息
type DingTalkMessage ¶
DingTalkMessage 消息
type EmailClient ¶
type EmailClient struct { Host string Port int Username string Password string Message *EmailMessage }
EmailClient 发送客户端
func NewEmailClient ¶
func NewEmailClient(host, username, password string, port int, message *EmailMessage) *EmailClient
NewEmailClient 返回一个邮件客户端 host smtp地址 username 用户名 password 密码 port 端口
func (*EmailClient) SendMessage ¶
func (c *EmailClient) SendMessage() (bool, error)
SendMessage 发送邮件
type EmailMessage ¶
type EmailMessage struct { From string To []string Cc []string Subject string ContentType string Content string Attach string }
EmailMessage 内容
func NewEmailMessage ¶
func NewEmailMessage(from, subject, contentType, content, attach string, to, cc []string) *EmailMessage
NewEmailMessage 返回消息对象 from: 发件人 subject: 标题 contentType: 内容的类型 text/plain text/html attach: 附件 to: 收件人 cc: 抄送人
type GoRSA ¶
type GoRSA struct { PublicKey *rsa.PublicKey PrivateKey *rsa.PrivateKey }
GoRSA RSA加密解密
func (*GoRSA) PrivateDecrypt ¶
PrivateDecrypt 私钥解密
func (*GoRSA) PublicEncrypt ¶
PublicEncrypt 公钥加密
type HLog ¶
type HLog struct { // log 路径 LogPath string // 日志类型 json|text 默认: json LogType string // 文件名的日期格式 默认: %Y-%m-%d|%Y%m%d FileNameDateFormat string // 日志中日期时间格式 默认: 2006-01-02 15:04:05 TimestampFormat string // 是否分离不同级别的日志 默认: true IsSeparateLevelLog bool // 日志级别 默认: log.InfoLevel LogLevel log.Level // 日志最长保存多久 默认: 15天 MaxAge time.Duration // 日志默认多长时间轮转一次 默认: 24小时 RotationTime time.Duration }
HLog 定义
func (*HLog) SetDateFormat ¶
SetDateFormat 设置日期格式 format "%Y-%m-%d" | "%Y%m%d"
func (*HLog) SetRotationTime ¶
SetRotationTime 设置日志多久轮转一次 单位: 天
func (*HLog) SetSeparateLevelLog ¶
SetSeparateLevelLog 设置是否分离不同级别的日志到不同的文件
type HLogger ¶
type HLogger struct{}
HLogger hlogger
type JWToken ¶
type JWToken struct {
SignString string
}
JWToken jwt token
func (*JWToken) GenJWToken ¶
GenJWToken 生成一个jwt token