This commit is contained in:
2023-05-11 21:28:34 +08:00
parent 2871fb556c
commit cf0d32bb32
5 changed files with 80 additions and 22 deletions

View File

@@ -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)
}