mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-18 19:50:25 +08:00
实现WAF
This commit is contained in:
37
internal/utils/string.go
Normal file
37
internal/utils/string.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// convert bytes to string
|
||||
func UnsafeBytesToString(bs []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&bs))
|
||||
}
|
||||
|
||||
// convert string to bytes
|
||||
func UnsafeStringToBytes(s string) []byte {
|
||||
return *(*[]byte)(unsafe.Pointer(&s))
|
||||
}
|
||||
|
||||
// format address
|
||||
func FormatAddress(addr string) string {
|
||||
if strings.HasSuffix(addr, "unix:") {
|
||||
return addr
|
||||
}
|
||||
addr = strings.Replace(addr, " ", "", -1)
|
||||
addr = strings.Replace(addr, "\t", "", -1)
|
||||
addr = strings.Replace(addr, ":", ":", -1)
|
||||
addr = strings.TrimSpace(addr)
|
||||
return addr
|
||||
}
|
||||
|
||||
// format address list
|
||||
func FormatAddressList(addrList []string) []string {
|
||||
result := []string{}
|
||||
for _, addr := range addrList {
|
||||
result = append(result, FormatAddress(addr))
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user