mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-01 10:00:19 +08:00
Add /api/get-message-answer API
This commit is contained in:
@ -20,6 +20,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -141,6 +142,16 @@ func GenerateSimpleTimeId() string {
|
||||
return t
|
||||
}
|
||||
|
||||
func GetRandomName() string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
const charset = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
result := make([]byte, 6)
|
||||
for i := range result {
|
||||
result[i] = charset[rand.Intn(len(charset))]
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func GetId(owner, name string) string {
|
||||
return fmt.Sprintf("%s/%s", owner, name)
|
||||
}
|
||||
|
14
util/time.go
14
util/time.go
@ -25,6 +25,20 @@ func GetCurrentTime() string {
|
||||
return tm.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func GetCurrentTimeEx(timestamp string) string {
|
||||
tm := time.Now()
|
||||
inputTime, err := time.Parse(time.RFC3339, timestamp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !tm.After(inputTime) {
|
||||
tm = inputTime.Add(1 * time.Millisecond)
|
||||
}
|
||||
|
||||
return tm.Format("2006-01-02T15:04:05.999Z07:00")
|
||||
}
|
||||
|
||||
func GetCurrentUnixTime() string {
|
||||
return strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
}
|
||||
|
Reference in New Issue
Block a user