parent
41cb6cfe63
commit
a5be2e6f7f
4 changed files with 57 additions and 15 deletions
@ -1,19 +1,49 @@ |
||||
package utils |
||||
|
||||
import( |
||||
logRotate "gopkg.in/natefinch/lumberjack.v2" |
||||
import ( |
||||
"net" |
||||
"fmt" |
||||
"strings" |
||||
|
||||
"pkg/libs/bytesize" |
||||
|
||||
logRotate "gopkg.in/natefinch/lumberjack.v2" |
||||
) |
||||
|
||||
const( |
||||
const ( |
||||
GolangSecurityTime = "2006-01-02T15:04:05Z" |
||||
// GolangSecurityTime = "2006-01-02 15:04:05"
|
||||
ReaderBufferSize = bytesize.MB * 32 |
||||
WriterBufferSize = bytesize.MB * 8 |
||||
) |
||||
|
||||
var( |
||||
var ( |
||||
Version = "$" |
||||
LogRotater *logRotate.Logger |
||||
StartTime string |
||||
) |
||||
|
||||
// read until hit the end of RESP: "\r\n"
|
||||
func ReadRESPEnd(c net.Conn) (string, error) { |
||||
var ret string |
||||
for { |
||||
b := make([]byte, 1) |
||||
if _, err := c.Read(b); err != nil { |
||||
return "", fmt.Errorf("read error[%v], current return[%s]", err, ret) |
||||
} |
||||
|
||||
ret += string(b) |
||||
if strings.HasSuffix(ret, "\r\n") { |
||||
break |
||||
} |
||||
} |
||||
return ret, nil |
||||
} |
||||
|
||||
func RemoveRESPEnd(input string) string { |
||||
length := len(input) |
||||
if length >= 2 { |
||||
return input[: length - 2] |
||||
} |
||||
return input |
||||
} |
Loading…
Reference in new issue