mirror of
https://gitee.com/johng/gf
synced 2026-06-09 02:57:43 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8906ff94a1 | |||
| 191ee39a06 | |||
| 87067e1e8a | |||
| edf90799d3 | |||
| c8cfa33bc7 | |||
| 14ce35f570 | |||
| 56db028b21 | |||
| 561bc5bc33 | |||
| 79ba162156 | |||
| 03bcf51a95 | |||
| 308fdccf65 |
57
.github/workflows/go.yml
vendored
57
.github/workflows/go.yml
vendored
@ -3,10 +3,11 @@ name: GoFrame CI
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- 'master'
|
||||
- 'develop'
|
||||
- 'fix/unsafe'
|
||||
pull_request:
|
||||
branches: [master, develop]
|
||||
branches: ['master', 'develop','fix/**']
|
||||
env:
|
||||
GF_DEBUG: 1
|
||||
|
||||
@ -16,7 +17,7 @@ jobs:
|
||||
# Service containers to run with `code-test`
|
||||
services:
|
||||
redis:
|
||||
image : redis
|
||||
image: redis
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
@ -28,7 +29,7 @@ jobs:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_DATABASE : test
|
||||
MYSQL_DATABASE: test
|
||||
MYSQL_ROOT_PASSWORD: 12345678
|
||||
ports:
|
||||
# Maps tcp port 3306 on service container to the host
|
||||
@ -37,35 +38,35 @@ jobs:
|
||||
# strategy set
|
||||
strategy:
|
||||
matrix:
|
||||
go: ["1.14", "1.15", "1.16"]
|
||||
go: [ "1.15", "1.16", "1.17" ]
|
||||
|
||||
steps:
|
||||
- name: Set Up Timezone
|
||||
uses: szenius/set-timezone@v1.0
|
||||
with:
|
||||
timezoneLinux: "Asia/Shanghai"
|
||||
- name: Set Up Timezone
|
||||
uses: szenius/set-timezone@v1.0
|
||||
with:
|
||||
timezoneLinux: "Asia/Shanghai"
|
||||
|
||||
- name: Checkout Repositary
|
||||
uses: actions/checkout@v2
|
||||
- name: Checkout Repositary
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set Up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
- name: Set Up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
- name: Before Script
|
||||
run: |
|
||||
date
|
||||
find . -name "*.go" | xargs gofmt -w
|
||||
git diff --name-only --exit-code || exit 1
|
||||
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts
|
||||
- name: Before Script
|
||||
run: |
|
||||
date
|
||||
find . -name "*.go" | xargs gofmt -w
|
||||
git diff --name-only --exit-code || exit 1
|
||||
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts
|
||||
|
||||
- name: Run i386 Arch Test
|
||||
run: GOARCH=386 go test -v ./... || exit 1
|
||||
- name: Run i386 Arch Test
|
||||
run: GOARCH=386 go test -v ./... || exit 1
|
||||
|
||||
- name: Run amd64 Arch Test
|
||||
run: GOARCH=amd64 go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
|
||||
- name: Run amd64 Arch Test
|
||||
run: GOARCH=amd64 go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
|
||||
|
||||
- name: Report Coverage
|
||||
run: bash <(curl -s https://codecov.io/bash)
|
||||
- name: Report Coverage
|
||||
run: bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
|
||||
6
.test/config.yaml
Normal file
6
.test/config.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
database:
|
||||
default:
|
||||
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||
|
||||
server:
|
||||
address: 127.0.0.1:8199
|
||||
16
.test/main.go
Normal file
16
.test/main.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fileContent := gfile.GetContents(`/Users/john/Workspace/Go/GOPATH/src/git.code.oa.com/Khaos/eros/app/khaos-oss/internal/logic/resource/resource_horizontal_downgrade.go`)
|
||||
matches, err := gregex.MatchAllString(`func \(\w+ (.+?)\) ([\s\S]+?) {`, fileContent)
|
||||
fmt.Println(err)
|
||||
g.Dump(matches)
|
||||
}
|
||||
@ -460,7 +460,7 @@ func (m *AnyAnyMap) Merge(other *AnyAnyMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *AnyAnyMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -458,7 +458,7 @@ func (m *IntAnyMap) Merge(other *IntAnyMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *IntAnyMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -429,7 +429,7 @@ func (m *IntIntMap) Merge(other *IntIntMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *IntIntMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -429,7 +429,7 @@ func (m *IntStrMap) Merge(other *IntStrMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *IntStrMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -454,7 +454,7 @@ func (m *StrAnyMap) Merge(other *StrAnyMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *StrAnyMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -432,7 +432,7 @@ func (m *StrIntMap) Merge(other *StrIntMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *StrIntMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -432,7 +432,7 @@ func (m *StrStrMap) Merge(other *StrStrMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *StrStrMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -513,7 +513,7 @@ func (m *ListMap) Merge(other *ListMap) {
|
||||
// String returns the map as a string.
|
||||
func (m *ListMap) String() string {
|
||||
b, _ := m.MarshalJSON()
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Byte is a struct for concurrent-safe operation for type byte.
|
||||
@ -60,12 +61,12 @@ func (v *Byte) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Byte) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatUint(uint64(v.Val()), 10)), nil
|
||||
return []byte(strconv.FormatUint(uint64(v.Val()), 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Byte) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Uint8(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Uint8(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -9,8 +9,9 @@ package gtype
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Bytes is a struct for concurrent-safe operation for type []byte.
|
||||
@ -59,7 +60,7 @@ func (v *Bytes) MarshalJSON() ([]byte, error) {
|
||||
val := v.Val()
|
||||
dst := make([]byte, base64.StdEncoding.EncodedLen(len(val)))
|
||||
base64.StdEncoding.Encode(dst, val)
|
||||
return gconv.UnsafeStrToBytes(`"` + gconv.UnsafeBytesToStr(dst) + `"`), nil
|
||||
return []byte(`"` + string(dst) + `"`), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
|
||||
@ -7,11 +7,12 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"math"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Float32 is a struct for concurrent-safe operation for type float32.
|
||||
@ -73,12 +74,12 @@ func (v *Float32) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Float32) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatFloat(float64(v.Val()), 'g', -1, 32)), nil
|
||||
return []byte(strconv.FormatFloat(float64(v.Val()), 'g', -1, 32)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Float32) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Float32(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Float32(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,11 +7,12 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"math"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Float64 is a struct for concurrent-safe operation for type float64.
|
||||
@ -73,12 +74,12 @@ func (v *Float64) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Float64) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatFloat(v.Val(), 'g', -1, 64)), nil
|
||||
return []byte(strconv.FormatFloat(v.Val(), 'g', -1, 64)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Float64) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Float64(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Float64(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Int is a struct for concurrent-safe operation for type int.
|
||||
@ -60,12 +61,12 @@ func (v *Int) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Int) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.Itoa(v.Val())), nil
|
||||
return []byte(strconv.Itoa(v.Val())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Int) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Int(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Int(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Int32 is a struct for concurrent-safe operation for type int32.
|
||||
@ -60,12 +61,12 @@ func (v *Int32) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Int32) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.Itoa(int(v.Val()))), nil
|
||||
return []byte(strconv.Itoa(int(v.Val()))), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Int32) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Int32(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Int32(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Int64 is a struct for concurrent-safe operation for type int64.
|
||||
@ -60,12 +61,12 @@ func (v *Int64) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Int64) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatInt(v.Val(), 10)), nil
|
||||
return []byte(strconv.FormatInt(v.Val(), 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Int64) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Int64(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Int64(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -8,8 +8,9 @@ package gtype
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// String is a struct for concurrent-safe operation for type string.
|
||||
@ -55,12 +56,12 @@ func (v *String) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *String) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(`"` + v.Val() + `"`), nil
|
||||
return []byte(`"` + v.Val() + `"`), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *String) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.UnsafeBytesToStr(bytes.Trim(b, `"`)))
|
||||
v.Set(string(bytes.Trim(b, `"`)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Uint is a struct for concurrent-safe operation for type uint.
|
||||
@ -60,12 +61,12 @@ func (v *Uint) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Uint) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatUint(uint64(v.Val()), 10)), nil
|
||||
return []byte(strconv.FormatUint(uint64(v.Val()), 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Uint) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Uint(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Uint(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Uint32 is a struct for concurrent-safe operation for type uint32.
|
||||
@ -60,12 +61,12 @@ func (v *Uint32) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Uint32) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatUint(uint64(v.Val()), 10)), nil
|
||||
return []byte(strconv.FormatUint(uint64(v.Val()), 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Uint32) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Uint32(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Uint32(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gtype
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Uint64 is a struct for concurrent-safe operation for type uint64.
|
||||
@ -60,12 +61,12 @@ func (v *Uint64) String() string {
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (v *Uint64) MarshalJSON() ([]byte, error) {
|
||||
return gconv.UnsafeStrToBytes(strconv.FormatUint(v.Val(), 10)), nil
|
||||
return []byte(strconv.FormatUint(v.Val(), 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||
func (v *Uint64) UnmarshalJSON(b []byte) error {
|
||||
v.Set(gconv.Uint64(gconv.UnsafeBytesToStr(b)))
|
||||
v.Set(gconv.Uint64(string(b)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package gdb
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/gogf/gf/container/gmap"
|
||||
"github.com/gogf/gf/encoding/gparser"
|
||||
"github.com/gogf/gf/internal/empty"
|
||||
@ -22,13 +23,13 @@ func (r Record) Interface() interface{} {
|
||||
// Json converts `r` to JSON format content.
|
||||
func (r Record) Json() string {
|
||||
content, _ := gparser.VarToJson(r.Map())
|
||||
return gconv.UnsafeBytesToStr(content)
|
||||
return string(content)
|
||||
}
|
||||
|
||||
// Xml converts `r` to XML format content.
|
||||
func (r Record) Xml(rootTag ...string) string {
|
||||
content, _ := gparser.VarToXml(r.Map(), rootTag...)
|
||||
return gconv.UnsafeBytesToStr(content)
|
||||
return string(content)
|
||||
}
|
||||
|
||||
// Map converts `r` to map[string]interface{}.
|
||||
|
||||
@ -8,15 +8,16 @@ package gredis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
"github.com/gogf/gf/errors/gcode"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Do sends a command to the server and returns the received reply.
|
||||
@ -117,7 +118,7 @@ func (c *Conn) ReceiveVarWithTimeout(timeout time.Duration) (*gvar.Var, error) {
|
||||
func resultToVar(result interface{}, err error) (*gvar.Var, error) {
|
||||
if err == nil {
|
||||
if result, ok := result.([]byte); ok {
|
||||
return gvar.New(gconv.UnsafeBytesToStr(result)), err
|
||||
return gvar.New(string(result)), err
|
||||
}
|
||||
// It treats all returned slice as string slice.
|
||||
if result, ok := result.([]interface{}); ok {
|
||||
|
||||
@ -58,7 +58,7 @@ func Benchmark_StackOfStdlib(b *testing.B) {
|
||||
|
||||
func Benchmark_StackWithFilter(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
StackWithFilter("test")
|
||||
StackWithFilter([]string{"test"})
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func Benchmark_Caller(b *testing.B) {
|
||||
|
||||
func Benchmark_CallerWithFilter(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
CallerWithFilter("test")
|
||||
CallerWithFilter([]string{"test"})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@ package gbase64
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
@ -27,7 +26,7 @@ func EncodeString(src string) string {
|
||||
|
||||
// EncodeToString encodes bytes to string with BASE64 algorithm.
|
||||
func EncodeToString(src []byte) string {
|
||||
return gconv.UnsafeBytesToStr(Encode(src))
|
||||
return string(Encode(src))
|
||||
}
|
||||
|
||||
// EncryptFile encodes file content of <path> using BASE64 algorithms.
|
||||
@ -55,7 +54,7 @@ func EncodeFileToString(path string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return gconv.UnsafeBytesToStr(content), nil
|
||||
return string(content), nil
|
||||
}
|
||||
|
||||
// MustEncodeFileToString encodes file content of <path> to string using BASE64 algorithms.
|
||||
@ -103,7 +102,7 @@ func MustDecodeString(data string) []byte {
|
||||
// DecodeString decodes string with BASE64 algorithm.
|
||||
func DecodeToString(data string) (string, error) {
|
||||
b, err := DecodeString(data)
|
||||
return gconv.UnsafeBytesToStr(b), err
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// MustDecodeToString decodes string with BASE64 algorithm.
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"github.com/gogf/gf/encoding/gxml"
|
||||
"github.com/gogf/gf/encoding/gyaml"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// ========================================================================
|
||||
@ -50,7 +49,7 @@ func (j *Json) MustToJson() []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToJsonString() string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToJson())
|
||||
return string(j.MustToJson())
|
||||
}
|
||||
|
||||
func (j *Json) MustToJsonIndent() []byte {
|
||||
@ -62,7 +61,7 @@ func (j *Json) MustToJsonIndent() []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToJsonIndentString() string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToJsonIndent())
|
||||
return string(j.MustToJsonIndent())
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
@ -96,7 +95,7 @@ func (j *Json) MustToXml(rootTag ...string) []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToXmlString(rootTag ...string) string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToXml(rootTag...))
|
||||
return string(j.MustToXml(rootTag...))
|
||||
}
|
||||
|
||||
func (j *Json) MustToXmlIndent(rootTag ...string) []byte {
|
||||
@ -108,7 +107,7 @@ func (j *Json) MustToXmlIndent(rootTag ...string) []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToXmlIndentString(rootTag ...string) string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToXmlIndent(rootTag...))
|
||||
return string(j.MustToXmlIndent(rootTag...))
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
@ -135,7 +134,7 @@ func (j *Json) MustToYaml() []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToYamlString() string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToYaml())
|
||||
return string(j.MustToYaml())
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
@ -162,7 +161,7 @@ func (j *Json) MustToToml() []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToTomlString() string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToToml())
|
||||
return string(j.MustToToml())
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
@ -189,5 +188,5 @@ func (j *Json) MustToIni() []byte {
|
||||
}
|
||||
|
||||
func (j *Json) MustToIniString() string {
|
||||
return gconv.UnsafeBytesToStr(j.MustToIni())
|
||||
return string(j.MustToIni())
|
||||
}
|
||||
|
||||
@ -9,6 +9,11 @@ package ghttp
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
"github.com/gogf/gf/encoding/gjson"
|
||||
"github.com/gogf/gf/encoding/gurl"
|
||||
@ -21,10 +26,6 @@ import (
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"github.com/gogf/gf/util/gvalid"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -174,7 +175,7 @@ func (r *Request) GetBody() []byte {
|
||||
// GetBodyString retrieves and returns request body content as string.
|
||||
// It can be called multiple times retrieving the same body content.
|
||||
func (r *Request) GetBodyString() string {
|
||||
return gconv.UnsafeBytesToStr(r.GetBody())
|
||||
return string(r.GetBody())
|
||||
}
|
||||
|
||||
// GetJson parses current request content as JSON format, and returns the JSON object.
|
||||
@ -374,7 +375,7 @@ func (r *Request) parseForm() {
|
||||
// It might be JSON/XML content.
|
||||
if s := gstr.Trim(name + strings.Join(values, " ")); len(s) > 0 {
|
||||
if s[0] == '{' && s[len(s)-1] == '}' || s[0] == '<' && s[len(s)-1] == '>' {
|
||||
r.bodyContent = gconv.UnsafeStrToBytes(s)
|
||||
r.bodyContent = []byte(s)
|
||||
params = ""
|
||||
break
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ghttp
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ghttp
|
||||
|
||||
@ -8,12 +8,11 @@ package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
)
|
||||
|
||||
// dumpTextFormat is the format of the dumped raw string
|
||||
@ -31,7 +30,7 @@ func getResponseBody(res *http.Response) string {
|
||||
}
|
||||
bodyContent, _ := ioutil.ReadAll(res.Body)
|
||||
res.Body = utils.NewReadCloser(bodyContent, true)
|
||||
return gconv.UnsafeBytesToStr(bodyContent)
|
||||
return string(bodyContent)
|
||||
}
|
||||
|
||||
// RawRequest returns the raw content of the request.
|
||||
@ -51,7 +50,7 @@ func (r *Response) RawRequest() string {
|
||||
return fmt.Sprintf(
|
||||
dumpTextFormat,
|
||||
"REQUEST ",
|
||||
gconv.UnsafeBytesToStr(bs),
|
||||
string(bs),
|
||||
r.requestBody,
|
||||
)
|
||||
}
|
||||
@ -70,7 +69,7 @@ func (r *Response) RawResponse() string {
|
||||
return fmt.Sprintf(
|
||||
dumpTextFormat,
|
||||
"RESPONSE",
|
||||
gconv.UnsafeBytesToStr(bs),
|
||||
string(bs),
|
||||
getResponseBody(r.Response),
|
||||
)
|
||||
}
|
||||
|
||||
@ -9,8 +9,6 @@ package client
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Response is the struct for client request response.
|
||||
@ -65,14 +63,13 @@ func (r *Response) ReadAll() []byte {
|
||||
|
||||
// ReadAllString retrieves and returns the response content as string.
|
||||
func (r *Response) ReadAllString() string {
|
||||
return gconv.UnsafeBytesToStr(r.ReadAll())
|
||||
return string(r.ReadAll())
|
||||
}
|
||||
|
||||
// Close closes the response when it will never be used.
|
||||
func (r *Response) Close() error {
|
||||
if r == nil || r.Response == nil || r.Response.Close {
|
||||
if r == nil || r.Response == nil {
|
||||
return nil
|
||||
}
|
||||
r.Response.Close = true
|
||||
return r.Response.Body.Close()
|
||||
}
|
||||
|
||||
@ -14,7 +14,6 @@ package gsmtp
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"net/smtp"
|
||||
"strings"
|
||||
)
|
||||
@ -85,7 +84,7 @@ func (s *SMTP) SendMail(from, tos, subject, body string, contentType ...string)
|
||||
header := map[string]string{
|
||||
"From": from,
|
||||
"To": strings.Join(tosArr, ";"),
|
||||
"Subject": fmt.Sprintf("=?UTF-8?B?%s?=", contentEncoding.EncodeToString(gconv.UnsafeStrToBytes(subject))),
|
||||
"Subject": fmt.Sprintf("=?UTF-8?B?%s?=", contentEncoding.EncodeToString([]byte(subject))),
|
||||
"MIME-Version": "1.0",
|
||||
"Content-Type": "text/plain; charset=UTF-8",
|
||||
"Content-Transfer-Encoding": "base64",
|
||||
@ -97,12 +96,12 @@ func (s *SMTP) SendMail(from, tos, subject, body string, contentType ...string)
|
||||
for k, v := range header {
|
||||
message += fmt.Sprintf("%s: %s\r\n", k, v)
|
||||
}
|
||||
message += "\r\n" + contentEncoding.EncodeToString(gconv.UnsafeStrToBytes(body))
|
||||
message += "\r\n" + contentEncoding.EncodeToString([]byte(body))
|
||||
return smtp.SendMail(
|
||||
address,
|
||||
smtp.PlainAuth("", s.Username, s.Password, server),
|
||||
from,
|
||||
tosArr,
|
||||
gconv.UnsafeStrToBytes(message),
|
||||
[]byte(message),
|
||||
)
|
||||
}
|
||||
|
||||
@ -11,8 +11,6 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -23,7 +21,7 @@ var (
|
||||
// GetContents returns the file content of <path> as string.
|
||||
// It returns en empty string if it fails reading.
|
||||
func GetContents(path string) string {
|
||||
return gconv.UnsafeBytesToStr(GetBytes(path))
|
||||
return string(GetBytes(path))
|
||||
}
|
||||
|
||||
// GetBytes returns the file content of <path> as []byte.
|
||||
|
||||
@ -11,10 +11,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/encoding/gbase64"
|
||||
"github.com/gogf/gf/encoding/gcompress"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
|
||||
"github.com/gogf/gf/os/gfile"
|
||||
)
|
||||
@ -116,7 +116,7 @@ func UnpackContent(content string) ([]*File, error) {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
data, err = gcompress.UnGzip(gconv.UnsafeStrToBytes(content))
|
||||
data, err = gcompress.UnGzip([]byte(content))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -166,7 +166,7 @@ func isHexStr(s string) bool {
|
||||
|
||||
// hexStrToBytes converts hex string content to []byte.
|
||||
func hexStrToBytes(s string) []byte {
|
||||
src := gconv.UnsafeStrToBytes(s)
|
||||
src := []byte(s)
|
||||
dst := make([]byte, hex.DecodedLen(len(src)))
|
||||
hex.Decode(dst, src)
|
||||
return dst
|
||||
|
||||
@ -9,9 +9,10 @@ package gview
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/util/gutil"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/encoding/ghtml"
|
||||
"github.com/gogf/gf/encoding/gurl"
|
||||
@ -222,7 +223,7 @@ func (view *View) buildInFuncNl2Br(str interface{}) string {
|
||||
// which encodes and returns `value` as JSON string.
|
||||
func (view *View) buildInFuncJson(value interface{}) (string, error) {
|
||||
b, err := json.Marshal(value)
|
||||
return gconv.UnsafeBytesToStr(b), err
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// buildInFuncPlus implements build-in template function: plus ,
|
||||
|
||||
@ -10,6 +10,11 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
htmltpl "html/template"
|
||||
"strconv"
|
||||
"strings"
|
||||
texttpl "text/template"
|
||||
|
||||
"github.com/gogf/gf/encoding/ghash"
|
||||
"github.com/gogf/gf/errors/gcode"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
@ -17,12 +22,7 @@ import (
|
||||
"github.com/gogf/gf/os/gfsnotify"
|
||||
"github.com/gogf/gf/os/gmlock"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"github.com/gogf/gf/util/gutil"
|
||||
htmltpl "html/template"
|
||||
"strconv"
|
||||
"strings"
|
||||
texttpl "text/template"
|
||||
|
||||
"github.com/gogf/gf/os/gres"
|
||||
|
||||
@ -71,7 +71,7 @@ func (view *View) Parse(ctx context.Context, file string, params ...Params) (res
|
||||
return nil
|
||||
}
|
||||
if resource != nil {
|
||||
content = gconv.UnsafeBytesToStr(resource.Content())
|
||||
content = string(resource.Content())
|
||||
} else {
|
||||
content = gfile.GetContentsWithCache(path)
|
||||
}
|
||||
|
||||
@ -7,14 +7,14 @@
|
||||
package guid
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"github.com/gogf/gf/encoding/ghash"
|
||||
"github.com/gogf/gf/net/gipv4"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"github.com/gogf/gf/util/grand"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"github.com/gogf/gf/encoding/ghash"
|
||||
"github.com/gogf/gf/net/gipv4"
|
||||
"github.com/gogf/gf/util/grand"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -94,7 +94,7 @@ func S(data ...[]byte) string {
|
||||
} else {
|
||||
panic("too many data parts, it should be no more than 2 parts")
|
||||
}
|
||||
return gconv.UnsafeBytesToStr(b)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// getSequence increases and returns the sequence string in 3 bytes.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package gf
|
||||
|
||||
const VERSION = "v1.16.7"
|
||||
const VERSION = "v1.16.9"
|
||||
const AUTHORS = "john<john@goframe.org>"
|
||||
|
||||
Reference in New Issue
Block a user