util

package
v0.0.0-...-7d1f1a1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 53 Imported by: 0

README

这个package 只能引用第三方package 或者标准库

不要 import internal 里面非 util 的package

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataToLarge     = errors.New("message too long for RSA public key size")
	ErrDataLen         = errors.New("data length error")
	ErrDataBroken      = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch = errors.New("data is not encrypted by the private key")
	ErrDecryption      = errors.New("decryption error")
	ErrPublicKey       = errors.New("get public key error")
	ErrPrivateKey      = errors.New("get private key error")
)
View Source
var RSA = &RSASecurity{}

Functions

func AesDecrypt

func AesDecrypt(encryptedB64UrlEncodingString string, k []byte) ([]byte, error)

AesDecrypt aes 解密 cryted 加密之后的b64-url-encoding 字符串 key 对称密钥 密钥长度必须 16/24/32 长度 返回 解密之后的string

func AesEncrypt

func AesEncrypt(origData, k []byte) (string, error)

AesEncrypt 加密bytes

func BcryptCompare

func BcryptCompare(input, hashedPassword string) error

BcryptCompare 比较密码

func BcryptPassword

func BcryptPassword(raw string) string

BcryptPassword hash密码

func BrowserOpen

func BrowserOpen(url string)

func CheckBindArg

func CheckBindArg(c *gin.Context, argPtr interface{}) bool

CheckBindArg 绑定参数并兼差错误

func CheckLicenseCode

func CheckLicenseCode(machineSN, licenseCode string, publicBs []byte) (bool, error)

func DesDecrypt

func DesDecrypt(decrypted string, key []byte) (string, error)

func DesEncrypt

func DesEncrypt(text string, key []byte) (string, error)

func GenerateLtsCertKeyPinPair

func GenerateLtsCertKeyPinPair(name string) (err error)

func GenerateTlsCert

func GenerateTlsCert() (*tls.Certificate, error)

生成证书密钥对 返回*tls.Certificate 做gRPC服务器启动时的参数

func GetHostName

func GetHostName() string

func GetUserName

func GetUserName() string

func GoogleTranslate

func GoogleTranslate(text string) (string, error)

func IsDirectory

func IsDirectory(path string) (bool, error)

func JSONCheckAuthErr

func JSONCheckAuthErr(c *gin.Context, err error) bool

JSONCheckAuthErr 检查错误

func JSONCheckBizErr

func JSONCheckBizErr(c *gin.Context, err error) bool

JSONCheckBizErr 检查错误 业务逻辑service错误的时候使用这个

func JSONCheckMwErr

func JSONCheckMwErr(c *gin.Context, err error) bool

JSONCheckMwErr gin middleware 报错

func JSONData

func JSONData(c *gin.Context, data interface{})

JSONData 返回成功数据

func JSONSuccess

func JSONSuccess(c *gin.Context)

JSONSuccess 响应成功数据

func KeyPairWithPin

func KeyPairWithPin() ([]byte, []byte, []byte, error)

KeyPairWithPin 返回 PEM证书 and PEM-Name 和SKPI(PIN码) 公共证书的指纹

func NewDingHook

func NewDingHook(url, app string, thresholdLevel logrus.Level) *dingHook

func NewSshClientConfig

func NewSshClientConfig(sshUser, sshPassword, sshType, sshKey, sshKeyPassword string) (config *ssh.ClientConfig, err error)

func ParamUint

func ParamUint(c *gin.Context, key string) (uint, error)

ParamUint 解析path-param中的参数到uint

func ParseUrlPage

func ParseUrlPage(href, div, jekyllDir string) error

func ParseUrlPageJianshu

func ParseUrlPageJianshu(href, div, jekyllDir string) error

func ParseUrlPageLibraGen

func ParseUrlPageLibraGen(href, div, jekyllDir string) error

func PriDecrypt

func PriDecrypt(src, privateKey []byte) ([]byte, error)

私钥解密

func PriEncrypt

func PriEncrypt(src, privateKey []byte) ([]byte, error)

私钥加密

func PubDecrypt

func PubDecrypt(src, publicKey []byte) ([]byte, error)

公钥解密

func PubEncrypt

func PubEncrypt(src, publicKey []byte) ([]byte, error)

公钥加密

func QueryInt

func QueryInt(c *gin.Context, key string) (int, error)

QueryInt 解析query中的参数到int

func RandString

func RandString(n int) string

RandString .

func RandStringDigit

func RandStringDigit(n int) string

func RandStringWordC

func RandStringWordC(n int) string

func RandStringWordL

func RandStringWordL(n int) string

func RandStringWordU

func RandStringWordU(n int) string

func RandomString

func RandomString(n int) string

func RemoveQInLines

func RemoveQInLines(lines []string) (res []string)

func RequestJson

func RequestJson(url, method string, reqBody interface{}, headersKv map[string]string) (*http.Response, error)

RequestJson 发送json参数

func RequestJsonString

func RequestJsonString(url, method string, reqBody string, headersKv map[string]string) (*http.Response, error)

RequestJsonString 发送json-string参数

func ResponseUnmarshal

func ResponseUnmarshal(resp *http.Response, vPtr interface{}) (bs []byte, err error)

ResponseUnmarshal 解析http response中的json

func Sha1String

func Sha1String(s string) string

func SshKeyPairGenerate

func SshKeyPairGenerate() (publicKeyString, privateKeyString string, err error)

SshKeyPairGenerate https://gist.github.com/devinodaniel/8f9b8a4f31573f428f29ec0e884e6673#file-gistfile1-txt-L29

func SshRemoteRunCommand

func SshRemoteRunCommand(sshClient *ssh.Client, command string) (string, error)

func SshdAuthByGithub

func SshdAuthByGithub(user string, key ssh.PublicKey) error

func WriteTtyRecData

func WriteTtyRecData(fd io.Writer, data []byte)

func ZeroPadding

func ZeroPadding(ciphertext []byte, blockSize int) []byte

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

type CmdLines

type CmdLines []string

type HTTPData

type HTTPData struct {
	Code int         `json:"code" example:"200"`
	Data interface{} `json:"data"`
}

HTTPData .

type HTTPError

type HTTPError struct {
	Code int    `json:"code" example:"203"` //203-用户认证错误 204-业务代码错误 205-中间件错误 206-参数错误
	Msg  string `json:"msg" example:"参数错误:..."`
}

HTTPError .

type HTTPSuccess

type HTTPSuccess struct {
	Code int    `json:"code" example:"200"`
	Msg  string `json:"msg" example:"ok"`
}

HTTPSuccess .

type JSONSliceString

type JSONSliceString []string

JSONSliceString gorm mysql >= 5.7 JSON字段映射的类型

func (*JSONSliceString) Scan

func (m *JSONSliceString) Scan(input interface{}) error

func (JSONSliceString) Value

func (m JSONSliceString) Value() (driver.Value, error)

type JSONSliceUint

type JSONSliceUint []uint

JSONSliceUint gorm mysql >= 5.7 JSON字段映射的类型

func (*JSONSliceUint) Scan

func (o *JSONSliceUint) Scan(input interface{}) error

Scan .

func (JSONSliceUint) Value

func (o JSONSliceUint) Value() (driver.Value, error)

Value .

type Option

type Option struct {
	PreFunc func(string) (string, error)
	ImgFunc func(alt, src, dataSrc string) (iAlt, iSrc string, err error)
	BaseUrl string
	Script  bool
	Style   bool
}

type Pagination

type Pagination struct {
	Size      int         `form:"size" json:"size"` //size 每页显示的数量
	Page      int         `form:"page" json:"page"` //page 页码
	Total     int64       `json:"total" form:"-"`   //total 分页的查询总的数量
	List      interface{} `json:"list" form:"-"`    //data 必须是[]interface{}指针
	Order     string      `form:"order" json:"-"`   //Order 排序字段 eg1: created_at:desc  eg2:id eg3: id:desc,updated_at
	Fields    string      `form:"fields" json:"-"`  //Fields 导出excel时候选择导出的column字段名数组, 使用英文逗号分隔
	CreatedAt []time.Time `form:"created_at[]" json:"created_at"`
	UpdatedAt []time.Time `form:"updated_at[]" json:"updated_at"`
	// contains filtered or unexported fields
}

Pagination 分页

func (*Pagination) Fetch

func (p *Pagination) Fetch(tx *gorm.DB, slicePtr interface{}) (err error)

Fetch 支持构建原始sql 可以保持软删除的一致性 tx gorm.DB 构造的自定义查询条件 slicePtr slice的指针引用 如果时间到字段的计算 请自定义Gorm AfterFind 钩子函数

type RSASecurity

type RSASecurity struct {
	// contains filtered or unexported fields
}

func (*RSASecurity) GetPrivatekey

func (r *RSASecurity) GetPrivatekey() (*rsa.PrivateKey, error)

*rsa.PublicKey

func (*RSASecurity) GetPublickey

func (r *RSASecurity) GetPublickey() (*rsa.PublicKey, error)

*rsa.PrivateKey

func (*RSASecurity) PriKeyDECRYPT

func (r *RSASecurity) PriKeyDECRYPT(input []byte) ([]byte, error)

私钥解密

func (*RSASecurity) PriKeyENCTYPT

func (r *RSASecurity) PriKeyENCTYPT(input []byte) ([]byte, error)

私钥加密

func (*RSASecurity) PubKeyDECRYPT

func (r *RSASecurity) PubKeyDECRYPT(input []byte) ([]byte, error)

公钥解密

func (*RSASecurity) PubKeyENCTYPT

func (r *RSASecurity) PubKeyENCTYPT(input []byte) ([]byte, error)

公钥加密

func (*RSASecurity) SetPrivateKey

func (r *RSASecurity) SetPrivateKey(priStr []byte) (err error)

设置私钥

func (*RSASecurity) SetPublicKey

func (r *RSASecurity) SetPublicKey(pubStr []byte) (err error)

设置公钥

type SshConn

type SshConn struct {
	// calling Write() to write data into ssh server
	StdinPipe io.WriteCloser
	// Write() be called to receive data from ssh server
	ComboOutput *wsBufferWriter
	Session     *ssh.Session
}

connect to ssh server using ssh session.

func NewSshConn

func NewSshConn(cols, rows int, sshClient *ssh.Client) (*SshConn, error)

setup ssh shell session set Session and StdinPipe here, and the Session.Stdout and Session.Sdterr are also set.

func (*SshConn) Close

func (s *SshConn) Close()

func (*SshConn) ReceiveWsMsg

func (ssConn *SshConn) ReceiveWsMsg(wsConn *websocket.Conn, logBuff *bytes.Buffer, exitCh chan bool)

ReceiveWsMsg receive websocket msg do some handling then write into ssh.session.stdin

func (*SshConn) SendComboOutput

func (ssConn *SshConn) SendComboOutput(wsConn *websocket.Conn, exitCh chan bool)

func (*SshConn) SessionWait

func (ssConn *SshConn) SessionWait(quitChan chan bool)

type Zippie

type Zippie struct {
	Base string
	// contains filtered or unexported fields
}

func NewZippie

func NewZippie(dir string) *Zippie

func (*Zippie) Close

func (z *Zippie) Close()

func (*Zippie) Zip

func (z *Zippie) Zip() (path string, f *os.File, err error)

Jump to

Keyboard shortcuts

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