1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package utils
- import (
- "gd_management_gateway/errors"
- "encoding/json"
- "fmt"
- "time"
- "unicode"
- )
- func GetUniqueLogID(cmd string) string {
- return fmt.Sprintf("%d_%s", time.Now().Unix(), cmd)
- }
- // 获取args对应的json字符串
- func MarshalJsonString(args ...interface{}) (result string) {
- if len(args) > 0 {
- if r, err := json.Marshal(args); err == nil {
- result = string(r)
- }
- }
- return
- }
- func VerifyPassword(pwd string) error {
- if len(pwd) < 8 {
- return errors.PasswordError
- }
- var (
- hasNumber bool
- hasLetter bool
- )
- for _, v := range pwd {
- switch {
- case unicode.IsNumber(v):
- hasNumber = true
- case unicode.IsLetter(v):
- hasLetter = true
- }
- }
- if !hasNumber || !hasLetter {
- return errors.PasswordError
- }
- return nil
- }
|