🚧 发布项目:随机字符串
This commit is contained in:
parent
9894cf758d
commit
4fe5e192f1
26
api/git.go
26
api/git.go
|
@ -1,12 +1,34 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/xuxiaowei-com-cn/cicd-release/constant"
|
||||
"crypto/rand"
|
||||
"log"
|
||||
"math/big"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// RandomString 随机字符串
|
||||
func RandomString(charset string, length int) string {
|
||||
// abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
|
||||
|
||||
result := ""
|
||||
charsetLength := big.NewInt(int64(len(charset)))
|
||||
for i := 0; i < length; i++ {
|
||||
randomIndex, err := rand.Int(rand.Reader, charsetLength)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
result += string(charset[randomIndex.Int64()])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// LowerCaseRandomString 小写随机字符串
|
||||
func LowerCaseRandomString(length int) string {
|
||||
charset := "abcdefghijklmnopqrstuvwxyz"
|
||||
return RandomString(charset, length)
|
||||
}
|
||||
|
||||
// GitVersion 获取 Git 版本号
|
||||
func GitVersion() (string, error) {
|
||||
cmd := exec.Command("git", "--version")
|
||||
|
|
Loading…
Reference in New Issue