mirror of
https://github.com/eolinker/apinto
synced 2025-10-21 15:59:27 +08:00
修改获取随机字符串的方法
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/valyala/fasthttp"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
s := &fasthttp.Server{
|
||||
Handler: func(ctx *fasthttp.RequestCtx) {
|
||||
|
||||
ctx.SetStatusCode(200)
|
||||
ctx.Write([]byte("ok"))
|
||||
},
|
||||
data := make([]byte, 8*1024*1024)
|
||||
for i := range data {
|
||||
data[i] = 1
|
||||
}
|
||||
s.ListenAndServe(":8082")
|
||||
fmt.Printf("n2 的类型 %T n2占中的大小是 %d G", data, unsafe.Sizeof(data))
|
||||
//s := &fasthttp.Server{
|
||||
// Handler: func(ctx *fasthttp.RequestCtx) {
|
||||
//
|
||||
// ctx.SetStatusCode(200)
|
||||
// ctx.Write([]byte("ok"))
|
||||
// },
|
||||
//}
|
||||
//s.ListenAndServe(":8082")
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package http_context
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"github.com/eolinker/goku-eosc/utils"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
@@ -27,14 +27,12 @@ type Context struct {
|
||||
|
||||
//NewContext 创建Context
|
||||
func NewContext(ctx *fasthttp.RequestCtx) *Context {
|
||||
id := uuid.NewV4()
|
||||
requestID := id.String()
|
||||
newRequest := &ctx.Request
|
||||
newCtx := &Context{
|
||||
context: ctx,
|
||||
requestOrg: fasthttp.AcquireRequest(),
|
||||
proxyRequest: fasthttp.AcquireRequest(),
|
||||
requestID: requestID,
|
||||
requestID: utils.GetRandomString(16),
|
||||
LogFields: access_field.NewFields(),
|
||||
}
|
||||
newRequest.CopyTo(newCtx.requestOrg)
|
||||
|
@@ -97,22 +97,21 @@ func GetRandomStringBack(num int) string {
|
||||
return string(result)
|
||||
}
|
||||
|
||||
const str = "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"
|
||||
var (
|
||||
randomBytes = []byte(str)
|
||||
randT = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randManager = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randBytes = []byte("123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ")
|
||||
randSize = len(randBytes)
|
||||
)
|
||||
|
||||
//GetRandomString 生成随机字符串
|
||||
func GetRandomString(num int) string {
|
||||
|
||||
result := make([]byte,num)
|
||||
|
||||
result := make([]byte, num)
|
||||
for i := 0; i < num; i++ {
|
||||
result[i] = randomBytes[int(randT.Int31())%num]
|
||||
result[i] = randBytes[int(randManager.Int31())%randSize]
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
//CheckFileIsExist 判断文件是否存在 存在返回 true 不存在返回false
|
||||
func CheckFileIsExist(filename string) bool {
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
|
Reference in New Issue
Block a user