b1c1e7b572
- Update the Go version requirements in `.github/workflows/gin.yml` - Remove test files for Go versions 1.18 and 1.19 - Update the required Go version in `debug.go` and `debug_test.go` - Rename and modify files related to Go version 1.19 and 1.20 in the `internal/bytesconv` directory Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
22 lines
719 B
Go
22 lines
719 B
Go
// Copyright 2023 Gin Core Team. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package bytesconv
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// StringToBytes converts string to byte slice without a memory allocation.
|
|
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
|
|
func StringToBytes(s string) []byte {
|
|
return unsafe.Slice(unsafe.StringData(s), len(s))
|
|
}
|
|
|
|
// BytesToString converts byte slice to string without a memory allocation.
|
|
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
|
|
func BytesToString(b []byte) string {
|
|
return unsafe.String(unsafe.SliceData(b), len(b))
|
|
}
|