slat
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -71,3 +72,18 @@ func LogComponent(startTime int64, r *http.Request) {
|
||||
url := fmt.Sprintf("\033[1;34m%s\033[0m", r.URL) // 藍色加重
|
||||
log.Println(method, url, endTime)
|
||||
}
|
||||
|
||||
// 隨機字串
|
||||
func RandomString(length int) string {
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = charset[RandomInt(0, len(charset)-1)]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// 隨機數字
|
||||
func RandomInt(min, max int) int {
|
||||
return min + rand.Intn(max-min+1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user