-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
38 lines (32 loc) · 891 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package bytego
import (
"path"
"unsafe"
)
func joinPath(basePath, relativePath string) string {
if relativePath == "" {
return basePath
}
finalPath := path.Join(basePath, relativePath)
if endWithChar(relativePath, '/') && !endWithChar(finalPath, '/') {
return finalPath + "/"
}
return finalPath
}
func endWithChar(str string, c byte) bool {
return str[len(str)-1] == c
}
// stringToBytes converts string to byte slice without a memory allocation.
func stringToBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(&s))
}
func bytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
func combineHandlers(handlers1, handlers2 []HandlerFunc) []HandlerFunc {
size := len(handlers1) + len(handlers2)
mergedHandlers := make([]HandlerFunc, size)
copy(mergedHandlers, handlers1)
copy(mergedHandlers[len(handlers1):], handlers2)
return mergedHandlers
}