mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
Merge pull request #1496 from bestgopher/update
modify:add stringToBytes Former-commit-id: fc34eb51edc1460f1e44107902698aa9f89c8d42
This commit is contained in:
commit
b02706f207
|
@ -3501,7 +3501,7 @@ func WriteJSON(writer io.Writer, v interface{}, options JSON, optimize bool) (in
|
|||
}
|
||||
|
||||
if prefix := options.Prefix; prefix != "" {
|
||||
result = append([]byte(prefix), result...)
|
||||
result = append(stringToBytes(prefix), result...)
|
||||
}
|
||||
|
||||
return writer.Write(result)
|
||||
|
@ -3512,6 +3512,10 @@ func bytesToString(b []byte) string {
|
|||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
|
||||
func stringToBytes(s string) []byte {
|
||||
return *(*[]byte)(unsafe.Pointer(&s))
|
||||
}
|
||||
|
||||
// DefaultJSONOptions is the optional settings that are being used
|
||||
// inside `ctx.JSON`.
|
||||
var DefaultJSONOptions = JSON{}
|
||||
|
@ -3564,7 +3568,7 @@ var finishCallbackB = []byte(");")
|
|||
// WriteJSONP marshals the given interface object and writes the JSON response to the writer.
|
||||
func WriteJSONP(writer io.Writer, v interface{}, options JSONP, optimize bool) (int, error) {
|
||||
if callback := options.Callback; callback != "" {
|
||||
n, err := writer.Write([]byte(callback + "("))
|
||||
n, err := writer.Write(stringToBytes(callback + "("))
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
|
@ -3671,7 +3675,7 @@ func (m xmlMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|||
// WriteXML marshals the given interface object and writes the XML response to the writer.
|
||||
func WriteXML(writer io.Writer, v interface{}, options XML, optimize bool) (int, error) {
|
||||
if prefix := options.Prefix; prefix != "" {
|
||||
n, err := writer.Write([]byte(prefix))
|
||||
n, err := writer.Write(stringToBytes(prefix))
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user