mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-26 17:36:35 +08:00
feat: 机器列表新增运行状态 & refactor: 登录账号信息存储与context
This commit is contained in:
@@ -5,11 +5,18 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const randChar = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
const Nums = "0123456789"
|
||||
const LowerChars = "abcdefghigklmnopqrstuvwxyz"
|
||||
const UpperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
// 生成随机字符串
|
||||
func Rand(l int) string {
|
||||
strList := []byte(randChar)
|
||||
return RandByChars(l, Nums+LowerChars+UpperChars)
|
||||
}
|
||||
|
||||
// 根据传入的chars,随机生成指定位数的字符串
|
||||
func RandByChars(l int, chars string) string {
|
||||
strList := []byte(chars)
|
||||
|
||||
result := []byte{}
|
||||
i := 0
|
||||
|
||||
26
server/pkg/utils/stringx/template_test.go
Normal file
26
server/pkg/utils/stringx/template_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package stringx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTemplateParse(t *testing.T) {
|
||||
tmpl := `
|
||||
{{if gt .cpu 10*5}}
|
||||
当前服务器[{{.asset.host}}]cpu使用率为{{.cpu}}
|
||||
{{end}}
|
||||
`
|
||||
vars := collx.M{
|
||||
"cpu": 60,
|
||||
"asset": collx.M{
|
||||
"host": "localhost:121",
|
||||
},
|
||||
}
|
||||
|
||||
res, _ := TemplateParse(tmpl, vars)
|
||||
res2 := strings.TrimSpace(res)
|
||||
fmt.Println(res2)
|
||||
}
|
||||
Reference in New Issue
Block a user