mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 20:22:20 +08:00
use raw string to bytes conversion
This commit is contained in:
parent
0397e5e0c0
commit
835d074ea7
6
auth.go
6
auth.go
@ -9,8 +9,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/internal/bytesconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AuthUserKey is the cookie name for user credential in basic auth.
|
// AuthUserKey is the cookie name for user credential in basic auth.
|
||||||
@ -34,7 +32,7 @@ func (a authPairs) searchCredential(authValue string) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
for _, pair := range a {
|
for _, pair := range a {
|
||||||
if subtle.ConstantTimeCompare(bytesconv.StringToBytes(pair.value), bytesconv.StringToBytes(authValue)) == 1 {
|
if subtle.ConstantTimeCompare([]byte(pair.value), []byte(authValue)) == 1 {
|
||||||
return pair.user, true
|
return pair.user, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +88,7 @@ func processAccounts(accounts Accounts) authPairs {
|
|||||||
|
|
||||||
func authorizationHeader(user, password string) string {
|
func authorizationHeader(user, password string) string {
|
||||||
base := user + ":" + password
|
base := user + ":" + password
|
||||||
return "Basic " + base64.StdEncoding.EncodeToString(bytesconv.StringToBytes(base))
|
return "Basic " + base64.StdEncoding.EncodeToString([]byte(base))
|
||||||
}
|
}
|
||||||
|
|
||||||
// BasicAuthForProxy returns a Basic HTTP Proxy-Authorization middleware.
|
// BasicAuthForProxy returns a Basic HTTP Proxy-Authorization middleware.
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/internal/bytesconv"
|
|
||||||
"github.com/gin-gonic/gin/internal/json"
|
"github.com/gin-gonic/gin/internal/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -239,9 +238,9 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel
|
|||||||
case multipart.FileHeader:
|
case multipart.FileHeader:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
|
return json.Unmarshal([]byte(val), value.Addr().Interface())
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())
|
return json.Unmarshal([]byte(val), value.Addr().Interface())
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
if !value.Elem().IsValid() {
|
if !value.Elem().IsValid() {
|
||||||
value.Set(reflect.New(value.Type().Elem()))
|
value.Set(reflect.New(value.Type().Elem()))
|
||||||
|
@ -97,9 +97,9 @@ func (r SecureJSON) Render(w http.ResponseWriter) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// if the jsonBytes is array values
|
// if the jsonBytes is array values
|
||||||
if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes,
|
if bytes.HasPrefix(jsonBytes, []byte("[")) && bytes.HasSuffix(jsonBytes,
|
||||||
bytesconv.StringToBytes("]")) {
|
[]byte("]")) {
|
||||||
if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil {
|
if _, err = w.Write([]byte(r.Prefix)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,11 +126,11 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callback := template.JSEscapeString(r.Callback)
|
callback := template.JSEscapeString(r.Callback)
|
||||||
if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil {
|
if _, err = w.Write([]byte(callback)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = w.Write(bytesconv.StringToBytes("(")); err != nil {
|
if _, err = w.Write([]byte("(")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = w.Write(bytesconv.StringToBytes(");")); err != nil {
|
if _, err = w.Write([]byte(");")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@ package render
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/internal/bytesconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// String contains the given interface object slice and its format.
|
// String contains the given interface object slice and its format.
|
||||||
@ -36,6 +34,6 @@ func WriteString(w http.ResponseWriter, format string, data []any) (err error) {
|
|||||||
_, err = fmt.Fprintf(w, format, data...)
|
_, err = fmt.Fprintf(w, format, data...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = w.Write(bytesconv.StringToBytes(format))
|
_, err = w.Write([]byte(format))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
4
tree.go
4
tree.go
@ -93,14 +93,14 @@ func (n *node) addChild(child *node) {
|
|||||||
|
|
||||||
func countParams(path string) uint16 {
|
func countParams(path string) uint16 {
|
||||||
var n uint16
|
var n uint16
|
||||||
s := bytesconv.StringToBytes(path)
|
s := []byte(path)
|
||||||
n += uint16(bytes.Count(s, strColon))
|
n += uint16(bytes.Count(s, strColon))
|
||||||
n += uint16(bytes.Count(s, strStar))
|
n += uint16(bytes.Count(s, strStar))
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func countSections(path string) uint16 {
|
func countSections(path string) uint16 {
|
||||||
s := bytesconv.StringToBytes(path)
|
s := []byte(path)
|
||||||
return uint16(bytes.Count(s, strSlash))
|
return uint16(bytes.Count(s, strSlash))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user