Documentation
¶
Index ¶
- Constants
- Variables
- func AfterStopFunc(d time.Duration, f func(<-chan struct{}))
- func AfterStopWithContext(d time.Duration, f func(context.Context))
- func Base64StdDecode(value []byte) ([]byte, error)
- func Base64StdEncode(value []byte) []byte
- func Base64URLDecode(value []byte) ([]byte, error)
- func Base64URLEncode(value []byte) []byte
- func BlockDecrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byte, error)
- func BlockEncrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byte, error)
- func BytesToStr(b []byte) string
- func CONNECT(pattern string, handlerFunc http.HandlerFunc)
- func Contains(str string, s []string) bool
- func DELETE(pattern string, handlerFunc http.HandlerFunc)
- func DecodePemHexBase64(data []byte) ([]byte, error)
- func DecryptByAesCBC(encrypted, key, iv []byte) (decrypted []byte, err error)
- func DecryptByAesCTR(origData, key []byte) (encrypted []byte, err error)
- func DecryptByRSA(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
- func DecryptByRSABytes(privateKey []byte, ciphertext []byte) ([]byte, error)
- func EncryptByAesCBC(origData, key, iv []byte) (encrypted []byte, err error)
- func EncryptByAesCTR(origData, key []byte) (encrypted []byte, err error)
- func EncryptByRSA(publicKey *rsa.PublicKey, content []byte) ([]byte, error)
- func EncryptByRSABytes(publicKey, content []byte) ([]byte, error)
- func FileCopy(source, dest string) (err error)
- func FileExist(file string) bool
- func FileFindPath(fname string) (string, error)
- func FileIsBinary(content string) bool
- func FileIsDir(path string) bool
- func FileMove(src, dest string) error
- func FileSize(path string) int64
- func FormatByStr(tpl string, t int64) string
- func FormatBytesString(b int64) string
- func FormatBytesStringOhMyGod(b int64) string
- func GET(pattern string, handlerFunc http.HandlerFunc)
- func GenerateBase64Key(secretLength SecretKeyLengthType, secretFormat SecretKeyFormatType) (pkStr, pbkStr string, err error)
- func GenerateECDSAKey(privateWriter, publicWriter io.Writer, c elliptic.Curve) error
- func GenerateECDSAKeyToMemory(c elliptic.Curve) (privateBytes []byte, publicBytes []byte, err error)
- func GenerateRSAKey(privateWriter, publicWriter io.Writer, bits RSABit) error
- func GenerateRSAKeyToMemory(bits RSABit) (privateBytes []byte, publicBytes []byte, err error)
- func GenerateSSHKey(bits RSABit) (pkBytes []byte, pbkBytes []byte, err error)
- func GetMonthRange(year, month int) (beginTime, endTime int64, err error)
- func GetWeek(t time.Time) int
- func HEAD(pattern string, handlerFunc http.HandlerFunc)
- func HMacMD5(data []byte, salt ...[]byte) string
- func HMacSha256(key []byte, value []byte) string
- func Handle(pattern string, handlerFunc http.HandlerFunc)
- func MD5(str []byte, salt ...[]byte) string
- func MacAddr() (upMac []string, err error)
- func NewServeMux() *http.ServeMux
- func OPTIONS(pattern string, handlerFunc http.HandlerFunc)
- func PATCH(pattern string, handlerFunc http.HandlerFunc)
- func POST(pattern string, handlerFunc http.HandlerFunc)
- func PUT(pattern string, handlerFunc http.HandlerFunc)
- func ParseRsaPrivateKey(derBytes []byte) (privateKey *rsa.PrivateKey, err error)
- func ParseRsaPublicKey(derBytes []byte) (publicKey *rsa.PublicKey, err error)
- func RandAlphaString(length int) string
- func RandBytes(length int) []byte
- func RandInt(min, max int) int
- func RandInt32(min, max int32) int32
- func RandInt64(min, max int64) int64
- func RandInts(from, to, size int) []int
- func RandLower(l int) string
- func RandString(n int) string
- func RandUpper(l int) string
- func Retry(n uint, interval time.Duration, fn func() error) (err error)
- func Round(x float64, place int32) float64
- func RsaPrivateDecrypt(privateKeyBytes, cipherBytes []byte) (textBytes []byte, err error)
- func RsaPublicEncrypt(publicKeyBytes, textBytes []byte) ([]byte, error)
- func SignByRSA(key *rsa.PrivateKey, licenseBytes []byte) (license string, err error)
- func SignByRSABytes(key, licenseBytes []byte) (string, error)
- func SignBySM2(privateKey *sm2.PrivateKey, licenseBytes []byte) (license string, err error)
- func SignBySM2Bytes(privateKey, licenseBytes []byte) (license string, err error)
- func StrToBytes(str string) []byte
- func StringReplaceIgnoreCase(text, source, target string) string
- func TRACE(pattern string, handlerFunc http.HandlerFunc)
- func TimeToStr(t time.Time, format ...string) string
- func TimestampToStr(t int64, format ...string) string
- func VerifyByRSA(publicKeyBase64, licenseCode string) (license string, valid bool, err error)
- func VerifyBySM2(publicKeyBase64, licenseCode string) (license string, valid bool, err error)
- func WithContext(ctx context.Context, n uint, interval time.Duration, fn func() error) (err error)
- type Audience
- type BlockStreamMode
- type Codec
- type GobEncoder
- type Header
- type IDGenerator
- type JSONEncoder
- type Payload
- type RSABit
- type SecretKeyFormatType
- type SecretKeyLengthType
- type Serializer
- type Time
Constants ¶
const ( Bytes = 1 KB = Bytes << 10 // 1 KB = 1024 Bytes MB = Bytes << 20 // 1 MB = 1048576 Bytes GB = Bytes << 30 // 1 GB = 1073741824 Bytes TB = Bytes << 40 // 1 TB = 1099511627776 Bytes PB = Bytes << 50 // 1 PB = 1125899906842624 Bytes EB = Bytes << 60 // 1 EB = 1152921504606846976 Bytes )
Variables ¶
Epoch is 01/01/1970.
var ErrMalformed = errors.New("jwt: malformed token")
ErrMalformed indicates a token doesn't have a valid format, as per the RFC 7519.
var ErrNotJSONObject = errors.New("jwt: payload is not a valid JSON object")
ErrNotJSONObject is the error for when a JWT payload is not a JSON object.
var ID id
Functions ¶
func AfterStopFunc ¶ added in v1.2.0
AfterStopFunc 超时停止协程,关闭协程。使用原始channel实现 这里新建了两个channel是防止关闭一个已经关闭的channel导致panic,这里还有优化点。 该函数主使用场景,比如防止扫描磁盘时间过长,在规定时间里获取结果.
func AfterStopWithContext ¶ added in v1.2.0
AfterStopWithContext 超时停止协程,关闭协程。使用context实现.
func Base64StdDecode ¶ added in v1.3.4
Base64StdDecode base标准解码
func Base64StdEncode ¶ added in v1.3.4
Base64StdEncode base标准编码
func Base64URLDecode ¶ added in v1.3.4
Base64URLDecode baseURL解码
func Base64URLEncode ¶ added in v1.3.4
Base64URLEncode baseURL编码
func BlockDecrypt ¶ added in v1.3.5
func BlockEncrypt ¶ added in v1.3.5
func CONNECT ¶ added in v1.2.0
func CONNECT(pattern string, handlerFunc http.HandlerFunc)
func DELETE ¶ added in v1.2.0
func DELETE(pattern string, handlerFunc http.HandlerFunc)
func DecodePemHexBase64 ¶
DecodePemHexBase64 解析pem或者hex或者base64编码成der编码.
func DecryptByAesCBC ¶ added in v1.3.5
DecryptByAesCBC cbc模式解密.
func DecryptByAesCTR ¶ added in v1.3.5
func DecryptByRSA ¶ added in v1.3.0
func DecryptByRSA(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
DecryptByRSA 使用RSA私钥解密.
func DecryptByRSABytes ¶ added in v1.3.0
DecryptByRSABytes 使用RSA私钥解密.
func EncryptByAesCBC ¶ added in v1.3.5
EncryptByAesCBC 加密 AES-128 key长度:16, 24, 32 bytes 对应 AES-128, AES-192, AES-256. CBC比EBC更安全,但不可并行.
func EncryptByAesCTR ¶ added in v1.3.5
func EncryptByRSA ¶ added in v1.3.0
EncryptByRSA 使用RSA公钥加密.
func EncryptByRSABytes ¶ added in v1.3.0
EncryptByRSABytes 使用RSA公钥加密.
func FileFindPath ¶
FileFindPath 获取文件名路径,首先判断文件是否可以直接访问,优先获取当前可执行文件夹下,再去找工作路径下.
func FormatByStr ¶
FormatByStr 将字符串中的时间变量(y年/m月/d日/h时/i分/s秒)转换成时间字符串.
func FormatBytesString ¶ added in v1.2.0
FormatBytesString 格式化bytes单位成可阅读单位形式,由于电脑制造商使用的是1000为单位计算磁盘大小 所以基本上使用该函数格式化存储大小.
func FormatBytesStringOhMyGod ¶ added in v1.2.0
FormatBytesStringOhMyGod 格式化存储大小,理论上应该使用该方式格式化存储大小,但是实际上不是这样的,呜呜呜呜呜呜.
func GET ¶ added in v1.2.0
func GET(pattern string, handlerFunc http.HandlerFunc)
func GenerateBase64Key ¶
func GenerateBase64Key(secretLength SecretKeyLengthType, secretFormat SecretKeyFormatType) (pkStr, pbkStr string, err error)
GenerateBase64Key 生成base64编码的公私钥.
func GenerateECDSAKey ¶ added in v1.3.4
GenerateECDSAKey 生成PEM格式ECDSA公私钥,写入到io.Writer中.
func GenerateECDSAKeyToMemory ¶ added in v1.3.4
func GenerateECDSAKeyToMemory(c elliptic.Curve) (privateBytes []byte, publicBytes []byte, err error)
GenerateECDSAKeyToMemory 生成PEM格式ECDSA公私钥,返回字节格式.
func GenerateRSAKey ¶ added in v1.3.0
GenerateRSAKey 生成PEM格式PKCS1的RSA公私钥,写入到io.Writer中.
func GenerateRSAKeyToMemory ¶ added in v1.3.0
GenerateRSAKeyToMemory 生成PEM格式PKCS1的RSA公私钥,返回字节格式.
func GenerateSSHKey ¶ added in v1.3.0
GenerateSSHKey 生成ssh密钥队.
func GetMonthRange ¶
GetMonthRange 获得指定年份和月份的起始unix时间和截止unix时间.
func HEAD ¶ added in v1.2.0
func HEAD(pattern string, handlerFunc http.HandlerFunc)
func HMacMD5 ¶ added in v1.3.5
HMacMD5 md5摘要算法,使用hmac算法生成hash,参数salt是多参数,实现多态的行为. 参考github.com/dxvgef/gommon/encrypt/sha.go中的hash算法.
func HMacSha256 ¶ added in v1.3.5
HMacSha256 生成hmac256摘要
func Handle ¶ added in v1.2.0
func Handle(pattern string, handlerFunc http.HandlerFunc)
func NewServeMux ¶ added in v1.2.0
func OPTIONS ¶ added in v1.2.0
func OPTIONS(pattern string, handlerFunc http.HandlerFunc)
func PATCH ¶ added in v1.2.0
func PATCH(pattern string, handlerFunc http.HandlerFunc)
func POST ¶ added in v1.2.0
func POST(pattern string, handlerFunc http.HandlerFunc)
func PUT ¶ added in v1.2.0
func PUT(pattern string, handlerFunc http.HandlerFunc)
func ParseRsaPrivateKey ¶ added in v1.3.4
func ParseRsaPrivateKey(derBytes []byte) (privateKey *rsa.PrivateKey, err error)
ParseRsaPrivateKey 解析私钥,derBytes可以使用DecodePemHexBase64函数获取.
func ParseRsaPublicKey ¶ added in v1.3.4
ParseRsaPublicKey 解析公钥,derBytes可以使用DecodePemHexBase64函数获取.
func Retry ¶ added in v1.2.0
Retry calls the `fn` and if it returns the error, retry to call `fn` after `interval` duration. The `fn` is called up to `n` times.
func RsaPrivateDecrypt ¶
RsaPrivateDecrypt 解析rsa私钥,参数privateKeyStr必须是hex、base64或者是pem编码.
func RsaPublicEncrypt ¶
RsaPublicEncrypt Rsa公钥加密,参数publicKeyStr必须是hex、base64或者是pem编码.
func SignByRSA ¶
func SignByRSA(key *rsa.PrivateKey, licenseBytes []byte) (license string, err error)
SignByRSA 使用rsa私钥对象指针签名字符串,返回base64编码的license.
func SignByRSABytes ¶
SignByRSABytes 使用rsa私钥签名字符串,返回base64编码的license.
func SignBySM2 ¶
func SignBySM2(privateKey *sm2.PrivateKey, licenseBytes []byte) (license string, err error)
SignBySM2 使用sm2私钥对象指针签名字符串,返回base64编码的license.
func SignBySM2Bytes ¶
SignBySM2Bytes 使用sm2私钥签名字符串,返回base64编码的license.
func StringReplaceIgnoreCase ¶
StringReplaceIgnoreCase 忽略大小写替换字符串.
func TRACE ¶ added in v1.2.0
func TRACE(pattern string, handlerFunc http.HandlerFunc)
func TimestampToStr ¶
TimestampToStr Timestamp将unix时间转为时间字符串.
func VerifyByRSA ¶
VerifyByRSA 使用rsa公钥验证签名的license.
func VerifyBySM2 ¶
VerifyBySM2 使用sm2公钥验证签名的license.
Types ¶
type Audience ¶ added in v1.3.5
type Audience []string
Audience is a special claim that may either be a single string or an array of strings, as per the RFC 7519.
func (Audience) MarshalJSON ¶ added in v1.3.5
MarshalJSON implements a marshaling function for "aud" claim.
func (*Audience) UnmarshalJSON ¶ added in v1.3.5
UnmarshalJSON implements an unmarshaling function for "aud" claim.
type BlockStreamMode ¶ added in v1.3.5
type BlockStreamMode string
const ( CTR BlockStreamMode = "CTR" CFB BlockStreamMode = "CFB" OFB BlockStreamMode = "OFB" RC4 BlockStreamMode = "RC4" )
type Codec ¶ added in v1.3.5
type Codec interface {
Encode(key, plaintext []byte) ([]byte, error)
Decode(key, ciphertext []byte) ([]byte, error)
}
func NewCookieCodec ¶ added in v1.3.5
func NewJwtCodec ¶ added in v1.3.5
type GobEncoder ¶ added in v1.3.5
type GobEncoder struct{}
GobEncoder encodes cookie values using encoding/gob. This is the simplest encoder and can handle complex types via gob.Register.
func (GobEncoder) Deserialize ¶ added in v1.3.5
func (e GobEncoder) Deserialize(src []byte, dst interface{}) error
Deserialize decodes a value using gob.
func (GobEncoder) Serialize ¶ added in v1.3.5
func (e GobEncoder) Serialize(src interface{}) ([]byte, error)
type IDGenerator ¶ added in v1.2.0
type JSONEncoder ¶ added in v1.3.5
type JSONEncoder struct{}
func (JSONEncoder) Deserialize ¶ added in v1.3.5
func (e JSONEncoder) Deserialize(src []byte, dst interface{}) error
Deserialize decodes a value using encoding/json.
func (JSONEncoder) Serialize ¶ added in v1.3.5
func (e JSONEncoder) Serialize(src interface{}) ([]byte, error)
Serialize encodes a value using encoding/json.
type Payload ¶ added in v1.3.5
type Payload struct {
Issuer string `json:"iss,omitempty"`
Subject string `json:"sub,omitempty"`
Audience Audience `json:"aud,omitempty"`
ExpirationTime *Time `json:"exp,omitempty"`
NotBefore *Time `json:"nbf,omitempty"`
IssuedAt *Time `json:"iat,omitempty"`
JWTID string `json:"jti,omitempty"`
}
Payload is a JWT payload according to the RFC 7519.
type SecretKeyFormatType ¶
type SecretKeyFormatType int
const ( PKCS8 SecretKeyFormatType = 1 PKCS1 SecretKeyFormatType = 2 )
func SecretKeyFormatTypeParse ¶
func SecretKeyFormatTypeParse(v int) SecretKeyFormatType
type SecretKeyLengthType ¶
type SecretKeyLengthType int
const ( RSA SecretKeyLengthType = 1 M2 SecretKeyLengthType = 2 )
func SecretKeyLengthTypeParse ¶
func SecretKeyLengthTypeParse(v int) SecretKeyLengthType
type Serializer ¶ added in v1.3.5
type Time ¶ added in v1.1.0
Time is the allowed format for time, as per the RFC 7519.
func NumericDate ¶ added in v1.1.0
NumericDate is a resolved Unix time.
func (Time) MarshalJSON ¶ added in v1.1.0
MarshalJSON implements a marshaling function for time-related claims.
func (*Time) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON implements an unmarshaling function for time-related claims.