Files
EdgeNode/internal/utils/string.go
GoEdgeLab 4245c73c47 实现WAF
2020-10-08 15:06:42 +08:00

38 lines
770 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}