mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 87067e1e8a | |||
| edf90799d3 | |||
| c8cfa33bc7 | |||
| 14ce35f570 | |||
| 56db028b21 | |||
| 561bc5bc33 | |||
| 79ba162156 | |||
| 03bcf51a95 | |||
| 308fdccf65 | |||
| fd92fd2409 | |||
| a2823a501e |
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 {
|
||||
|
||||
@ -8,7 +8,6 @@ package gdebug
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -34,7 +33,7 @@ func init() {
|
||||
goRootForFilter = strings.Replace(goRootForFilter, "\\", "/", -1)
|
||||
}
|
||||
// Initialize internal package variable: selfPath.
|
||||
selfPath, _ := exec.LookPath(os.Args[0])
|
||||
selfPath, _ = exec.LookPath(os.Args[0])
|
||||
if selfPath != "" {
|
||||
selfPath, _ = filepath.Abs(selfPath)
|
||||
}
|
||||
@ -46,14 +45,14 @@ func init() {
|
||||
// Caller returns the function name and the absolute file path along with its line
|
||||
// number of the caller.
|
||||
func Caller(skip ...int) (function string, path string, line int) {
|
||||
return CallerWithFilter("", skip...)
|
||||
return CallerWithFilter(nil, skip...)
|
||||
}
|
||||
|
||||
// CallerWithFilter returns the function name and the absolute file path along with
|
||||
// its line number of the caller.
|
||||
//
|
||||
// The parameter `filter` is used to filter the path of the caller.
|
||||
func CallerWithFilter(filter string, skip ...int) (function string, path string, line int) {
|
||||
// The parameter `filters` is used to filter the path of the caller.
|
||||
func CallerWithFilter(filters []string, skip ...int) (function string, path string, line int) {
|
||||
var (
|
||||
number = 0
|
||||
ok = true
|
||||
@ -61,14 +60,17 @@ func CallerWithFilter(filter string, skip ...int) (function string, path string,
|
||||
if len(skip) > 0 {
|
||||
number = skip[0]
|
||||
}
|
||||
pc, file, line, start := callerFromIndex([]string{filter})
|
||||
pc, file, line, start := callerFromIndex(filters)
|
||||
if start != -1 {
|
||||
for i := start + number; i < maxCallerDepth; i++ {
|
||||
if i != start {
|
||||
pc, file, line, ok = runtime.Caller(i)
|
||||
}
|
||||
if ok {
|
||||
function := ""
|
||||
if filterFileByFilters(file, filters) {
|
||||
continue
|
||||
}
|
||||
function = ""
|
||||
if fn := runtime.FuncForPC(pc); fn == nil {
|
||||
function = "unknown"
|
||||
} else {
|
||||
@ -86,30 +88,14 @@ func CallerWithFilter(filter string, skip ...int) (function string, path string,
|
||||
// callerFromIndex returns the caller position and according information exclusive of the
|
||||
// debug package.
|
||||
//
|
||||
// VERY NOTE THAT, the returned index value should be <index - 1> as the caller's start point.
|
||||
// VERY NOTE THAT, the returned index value should be `index - 1` as the caller's start point.
|
||||
func callerFromIndex(filters []string) (pc uintptr, file string, line int, index int) {
|
||||
var filtered, ok bool
|
||||
var ok bool
|
||||
for index = 0; index < maxCallerDepth; index++ {
|
||||
if pc, file, line, ok = runtime.Caller(index); ok {
|
||||
filtered = false
|
||||
for _, filter := range filters {
|
||||
if filter != "" && strings.Contains(file, filter) {
|
||||
filtered = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if filtered {
|
||||
if filterFileByFilters(file, filters) {
|
||||
continue
|
||||
}
|
||||
if !utils.IsDebugEnabled() {
|
||||
if strings.Contains(file, utils.StackFilterKeyForGoFrame) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(file, stackFilterKey) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if index > 0 {
|
||||
index--
|
||||
}
|
||||
@ -119,6 +105,27 @@ func callerFromIndex(filters []string) (pc uintptr, file string, line int, index
|
||||
return 0, "", -1, -1
|
||||
}
|
||||
|
||||
func filterFileByFilters(file string, filters []string) (filtered bool) {
|
||||
// Filter empty file.
|
||||
if file == "" {
|
||||
return true
|
||||
}
|
||||
// Filter gdebug package callings.
|
||||
if strings.Contains(file, stackFilterKey) {
|
||||
return true
|
||||
}
|
||||
for _, filter := range filters {
|
||||
if filter != "" && strings.Contains(file, filter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// GOROOT filter.
|
||||
if goRootForFilter != "" && len(file) >= len(goRootForFilter) && file[0:len(goRootForFilter)] == goRootForFilter {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CallerPackage returns the package name of the caller.
|
||||
func CallerPackage() string {
|
||||
function, _, _ := Caller()
|
||||
|
||||
@ -9,9 +9,7 @@ package gdebug
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PrintStack prints to standard error the stack trace returned by runtime.Stack.
|
||||
@ -22,15 +20,15 @@ func PrintStack(skip ...int) {
|
||||
// Stack returns a formatted stack trace of the goroutine that calls it.
|
||||
// It calls runtime.Stack with a large enough buffer to capture the entire trace.
|
||||
func Stack(skip ...int) string {
|
||||
return StackWithFilter("", skip...)
|
||||
return StackWithFilter(nil, skip...)
|
||||
}
|
||||
|
||||
// StackWithFilter returns a formatted stack trace of the goroutine that calls it.
|
||||
// It calls runtime.Stack with a large enough buffer to capture the entire trace.
|
||||
//
|
||||
// The parameter `filter` is used to filter the path of the caller.
|
||||
func StackWithFilter(filter string, skip ...int) string {
|
||||
return StackWithFilters([]string{filter}, skip...)
|
||||
func StackWithFilter(filters []string, skip ...int) string {
|
||||
return StackWithFilters(filters, skip...)
|
||||
}
|
||||
|
||||
// StackWithFilters returns a formatted stack trace of the goroutine that calls it.
|
||||
@ -50,7 +48,6 @@ func StackWithFilters(filters []string, skip ...int) string {
|
||||
space = " "
|
||||
index = 1
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
filtered = false
|
||||
ok = true
|
||||
pc, file, line, start = callerFromIndex(filters)
|
||||
)
|
||||
@ -59,38 +56,9 @@ func StackWithFilters(filters []string, skip ...int) string {
|
||||
pc, file, line, ok = runtime.Caller(i)
|
||||
}
|
||||
if ok {
|
||||
// Filter empty file.
|
||||
if file == "" {
|
||||
if filterFileByFilters(file, filters) {
|
||||
continue
|
||||
}
|
||||
// GOROOT filter.
|
||||
if goRootForFilter != "" &&
|
||||
len(file) >= len(goRootForFilter) &&
|
||||
file[0:len(goRootForFilter)] == goRootForFilter {
|
||||
continue
|
||||
}
|
||||
// Custom filtering.
|
||||
filtered = false
|
||||
for _, filter := range filters {
|
||||
if filter != "" && strings.Contains(file, filter) {
|
||||
filtered = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if filtered {
|
||||
continue
|
||||
}
|
||||
|
||||
if !utils.IsDebugEnabled() {
|
||||
if strings.Contains(file, utils.StackFilterKeyForGoFrame) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(file, stackFilterKey) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if fn := runtime.FuncForPC(pc); fn == nil {
|
||||
name = "unknown"
|
||||
} else {
|
||||
|
||||
@ -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())
|
||||
}
|
||||
|
||||
7
go.mod
7
go.mod
@ -10,11 +10,10 @@ require (
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gomodule/redigo v1.8.5
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf
|
||||
github.com/grokify/html-strip-tags-go v0.0.1
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
go.opentelemetry.io/otel v1.0.0-RC2
|
||||
go.opentelemetry.io/otel/oteltest v1.0.0-RC2
|
||||
go.opentelemetry.io/otel/trace v1.0.0-RC2
|
||||
go.opentelemetry.io/otel v1.0.0
|
||||
go.opentelemetry.io/otel/trace v1.0.0
|
||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023
|
||||
golang.org/x/text v0.3.6
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
|
||||
14
go.sum
14
go.sum
@ -16,8 +16,8 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf h1:wIOAyJMMen0ELGiFzlmqxdcV1yGbkyHBAB6PolcNbLA=
|
||||
github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
@ -32,12 +32,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.opentelemetry.io/otel v1.0.0-RC2 h1:SHhxSjB+omnGZPgGlKe+QMp3MyazcOHdQ8qwo89oKbg=
|
||||
go.opentelemetry.io/otel v1.0.0-RC2/go.mod h1:w1thVQ7qbAy8MHb0IFj8a5Q2QU0l2ksf8u/CN8m3NOM=
|
||||
go.opentelemetry.io/otel/oteltest v1.0.0-RC2 h1:xNKqMhlZYkASSyvF4JwObZFMq0jhFN3c3SP+2rCzVPk=
|
||||
go.opentelemetry.io/otel/oteltest v1.0.0-RC2/go.mod h1:kiQ4tw5tAL4JLTbcOYwK1CWI1HkT5aiLzHovgOVnz/A=
|
||||
go.opentelemetry.io/otel/trace v1.0.0-RC2 h1:dunAP0qDULMIT82atj34m5RgvsIK6LcsXf1c/MsYg1w=
|
||||
go.opentelemetry.io/otel/trace v1.0.0-RC2/go.mod h1:JPQ+z6nNw9mqEGT8o3eoPTdnNI+Aj5JcxEsVGREIAy4=
|
||||
go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI=
|
||||
go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg=
|
||||
go.opentelemetry.io/otel/trace v1.0.0 h1:TSBr8GTEtKevYMG/2d21M989r5WJYVimhTHBKVEZuh4=
|
||||
go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs=
|
||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 h1:ADo5wSpq2gqaCGQWzk7S5vd//0iyyLeAratkEoG5dLE=
|
||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
@ -11,11 +11,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -43,23 +45,35 @@ func SetEnabled(enabled bool) {
|
||||
// Print prints `v` with newline using fmt.Println.
|
||||
// The parameter `v` can be multiple variables.
|
||||
func Print(ctx context.Context, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprint(v...), false)
|
||||
}
|
||||
|
||||
// Printf prints `v` with format `format` using fmt.Printf.
|
||||
// The parameter `v` can be multiple variables.
|
||||
func Printf(ctx context.Context, format string, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprintf(format, v...), false)
|
||||
}
|
||||
|
||||
// Error prints `v` with newline using fmt.Println.
|
||||
// The parameter `v` can be multiple variables.
|
||||
func Error(ctx context.Context, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprint(v...), true)
|
||||
}
|
||||
|
||||
// Errorf prints `v` with format `format` using fmt.Printf.
|
||||
func Errorf(ctx context.Context, format string, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprintf(format, v...), true)
|
||||
}
|
||||
|
||||
@ -94,7 +108,7 @@ func doPrint(ctx context.Context, content string, stack bool) {
|
||||
return
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
buffer.WriteString(now())
|
||||
buffer.WriteString(time.Now().Format("2006-01-02 15:04:05.000"))
|
||||
buffer.WriteString(" [INTE] ")
|
||||
buffer.WriteString(file())
|
||||
buffer.WriteString(" ")
|
||||
@ -104,7 +118,7 @@ func doPrint(ctx context.Context, content string, stack bool) {
|
||||
buffer.WriteString(content)
|
||||
buffer.WriteString("\n")
|
||||
if stack {
|
||||
buffer.WriteString(gdebug.StackWithFilter(stackFilterKey))
|
||||
buffer.WriteString(gdebug.StackWithFilter([]string{stackFilterKey}))
|
||||
}
|
||||
fmt.Print(buffer.String())
|
||||
}
|
||||
@ -121,13 +135,8 @@ func traceIdStr(ctx context.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// now returns current time string.
|
||||
func now() string {
|
||||
return time.Now().Format("2006-01-02 15:04:05.000")
|
||||
}
|
||||
|
||||
// file returns caller file name along with its line number.
|
||||
func file() string {
|
||||
_, p, l := gdebug.CallerWithFilter(stackFilterKey)
|
||||
_, p, l := gdebug.CallerWithFilter([]string{stackFilterKey})
|
||||
return fmt.Sprintf(`%s:%d`, filepath.Base(p), l)
|
||||
}
|
||||
|
||||
@ -8,19 +8,21 @@ package ghttp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/gogf/gf"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"github.com/gogf/gf/net/ghttp/internal/client"
|
||||
"github.com/gogf/gf/net/ghttp/internal/httputil"
|
||||
"github.com/gogf/gf/net/gtrace"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -56,8 +58,8 @@ func MiddlewareServerTracing(r *Request) {
|
||||
r.Body = utils.NewReadCloser(reqBodyContentBytes, false)
|
||||
|
||||
span.AddEvent(tracingEventHttpRequest, trace.WithAttributes(
|
||||
attribute.Any(tracingEventHttpRequestHeaders, httputil.HeaderToMap(r.Header)),
|
||||
attribute.Any(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ctx)),
|
||||
attribute.String(tracingEventHttpRequestHeaders, gconv.String(httputil.HeaderToMap(r.Header))),
|
||||
attribute.String(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ctx).String()),
|
||||
attribute.String(tracingEventHttpRequestBody, gstr.StrLimit(
|
||||
string(reqBodyContentBytes),
|
||||
gtrace.MaxContentLogSize(),
|
||||
@ -82,7 +84,7 @@ func MiddlewareServerTracing(r *Request) {
|
||||
)
|
||||
|
||||
span.AddEvent(tracingEventHttpResponse, trace.WithAttributes(
|
||||
attribute.Any(tracingEventHttpResponseHeaders, httputil.HeaderToMap(r.Response.Header())),
|
||||
attribute.String(tracingEventHttpResponseHeaders, gconv.String(httputil.HeaderToMap(r.Response.Header()))),
|
||||
attribute.String(tracingEventHttpResponseBody, resBodyContent),
|
||||
))
|
||||
return
|
||||
|
||||
@ -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,10 +8,11 @@ package ghttp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"github.com/gogf/gf/errors/gcode"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
|
||||
@ -69,7 +70,7 @@ func (s *Server) parsePattern(pattern string) (domain, method, path string, err
|
||||
func (s *Server) setHandler(pattern string, handler *handlerItem) {
|
||||
handler.Id = handlerIdGenerator.Add(1)
|
||||
if handler.Source == "" {
|
||||
_, file, line := gdebug.CallerWithFilter(stackFilterKey)
|
||||
_, file, line := gdebug.CallerWithFilter([]string{stackFilterKey})
|
||||
handler.Source = fmt.Sprintf(`%s:%d`, file, line)
|
||||
}
|
||||
domain, method, uri, err := s.parsePattern(pattern)
|
||||
|
||||
@ -8,10 +8,11 @@ package ghttp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
@ -264,7 +265,7 @@ func (g *RouterGroup) Middleware(handlers ...HandlerFunc) *RouterGroup {
|
||||
|
||||
// preBindToLocalArray adds the route registering parameters to internal variable array for lazily registering feature.
|
||||
func (g *RouterGroup) preBindToLocalArray(bindType string, pattern string, object interface{}, params ...interface{}) *RouterGroup {
|
||||
_, file, line := gdebug.CallerWithFilter(stackFilterKey)
|
||||
_, file, line := gdebug.CallerWithFilter([]string{stackFilterKey})
|
||||
preBindItems = append(preBindItems, &preBindItem{
|
||||
group: g,
|
||||
bindType: bindType,
|
||||
|
||||
@ -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,7 +63,7 @@ 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.
|
||||
|
||||
@ -8,19 +8,21 @@ package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
|
||||
"github.com/gogf/gf"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"github.com/gogf/gf/net/ghttp/internal/httputil"
|
||||
"github.com/gogf/gf/net/gtrace"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -70,7 +72,7 @@ func MiddlewareTracing(c *Client, r *http.Request) (response *Response, err erro
|
||||
response.Body = utils.NewReadCloser(reqBodyContentBytes, false)
|
||||
|
||||
span.AddEvent(tracingEventHttpResponse, trace.WithAttributes(
|
||||
attribute.Any(tracingEventHttpResponseHeaders, httputil.HeaderToMap(response.Header)),
|
||||
attribute.String(tracingEventHttpResponseHeaders, gconv.String(httputil.HeaderToMap(response.Header))),
|
||||
attribute.String(tracingEventHttpResponseBody, gstr.StrLimit(
|
||||
string(reqBodyContentBytes),
|
||||
gtrace.MaxContentLogSize(),
|
||||
|
||||
@ -10,18 +10,20 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"github.com/gogf/gf/net/gtrace"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"github.com/gogf/gf/net/gtrace"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type clientTracer struct {
|
||||
@ -147,8 +149,8 @@ func (ct *clientTracer) wroteRequest(info httptrace.WroteRequestInfo) {
|
||||
}
|
||||
|
||||
ct.span.AddEvent(tracingEventHttpRequest, trace.WithAttributes(
|
||||
attribute.Any(tracingEventHttpRequestHeaders, ct.headers),
|
||||
attribute.Any(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ct.Context)),
|
||||
attribute.String(tracingEventHttpRequestHeaders, gconv.String(ct.headers)),
|
||||
attribute.String(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ct.Context).String()),
|
||||
attribute.String(tracingEventHttpRequestBody, gstr.StrLimit(
|
||||
string(ct.requestBody),
|
||||
gtrace.MaxContentLogSize(),
|
||||
|
||||
@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
@ -8,12 +8,13 @@ package gtrace_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/net/gtrace"
|
||||
"github.com/gogf/gf/test/gtest"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/oteltest"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -51,14 +52,17 @@ func TestNewCarrier(t *testing.T) {
|
||||
SpanID: spanID,
|
||||
TraceFlags: trace.FlagsSampled,
|
||||
}))
|
||||
ctx, _ = oteltest.DefaultTracer().Start(ctx, "inject")
|
||||
sc := trace.SpanContextFromContext(ctx)
|
||||
t.Assert(sc.TraceID().String(), traceID.String())
|
||||
t.Assert(sc.SpanID().String(), "00f067aa0ba902b7")
|
||||
|
||||
ctx, _ = otel.Tracer("").Start(ctx, "inject")
|
||||
carrier1 := gtrace.NewCarrier()
|
||||
otel.GetTextMapPropagator().Inject(ctx, carrier1)
|
||||
t.Assert(carrier1.String(), `{"traceparent":"00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000002-01"}`)
|
||||
|
||||
ctx = otel.GetTextMapPropagator().Extract(ctx, carrier1)
|
||||
gotSc := trace.SpanContextFromContext(ctx)
|
||||
t.Assert(gotSc.TraceID().String(), traceID.String())
|
||||
t.Assert(gotSc.SpanID().String(), "0000000000000002")
|
||||
// New span is created internally, so the SpanID is different.
|
||||
})
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -10,6 +10,11 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
@ -18,10 +23,6 @@ import (
|
||||
"github.com/gogf/gf/os/gmlock"
|
||||
"github.com/gogf/gf/os/gtimer"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
|
||||
@ -152,7 +153,7 @@ func (l *Logger) print(ctx context.Context, level int, values ...interface{}) {
|
||||
|
||||
// Caller path and Fn name.
|
||||
if l.config.Flags&(F_FILE_LONG|F_FILE_SHORT|F_CALLER_FN) > 0 {
|
||||
callerFnName, path, line := gdebug.CallerWithFilter(pathFilterKey, l.config.StSkip)
|
||||
callerFnName, path, line := gdebug.CallerWithFilter([]string{pathFilterKey}, l.config.StSkip)
|
||||
if l.config.Flags&F_CALLER_FN > 0 {
|
||||
if len(callerFnName) > 2 {
|
||||
input.CallerFunc = fmt.Sprintf(`[%s]`, callerFnName)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -8,13 +8,14 @@ package gtest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/empty"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
|
||||
"github.com/gogf/gf/internal/empty"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
@ -22,33 +23,19 @@ const (
|
||||
pathFilterKey = "/test/gtest/gtest"
|
||||
)
|
||||
|
||||
// C creates an unit testing case.
|
||||
// C creates a unit testing case.
|
||||
// The parameter `t` is the pointer to testing.T of stdlib (*testing.T).
|
||||
// The parameter `f` is the closure function for unit testing case.
|
||||
func C(t *testing.T, f func(t *T)) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter(pathFilterKey))
|
||||
_, _ = fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter([]string{pathFilterKey}))
|
||||
t.Fail()
|
||||
}
|
||||
}()
|
||||
f(&T{t})
|
||||
}
|
||||
|
||||
// Case creates an unit testing case.
|
||||
// The parameter `t` is the pointer to testing.T of stdlib (*testing.T).
|
||||
// The parameter `f` is the closure function for unit testing case.
|
||||
// Deprecated.
|
||||
func Case(t *testing.T, f func()) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter(pathFilterKey))
|
||||
t.Fail()
|
||||
}
|
||||
}()
|
||||
f()
|
||||
}
|
||||
|
||||
// Assert checks `value` and `expect` EQUAL.
|
||||
func Assert(value, expect interface{}) {
|
||||
rvExpect := reflect.ValueOf(expect)
|
||||
@ -302,7 +289,7 @@ func Error(message ...interface{}) {
|
||||
|
||||
// Fatal prints `message` to stderr and exit the process.
|
||||
func Fatal(message ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, "[FATAL] %s\n%s", fmt.Sprint(message...), gdebug.StackWithFilter(pathFilterKey))
|
||||
fmt.Fprintf(os.Stderr, "[FATAL] %s\n%s", fmt.Sprint(message...), gdebug.StackWithFilter([]string{pathFilterKey}))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -357,3 +344,28 @@ func AssertNil(value interface{}) {
|
||||
}
|
||||
AssertNE(value, nil)
|
||||
}
|
||||
|
||||
// DataPath retrieves and returns the testdata path of current package,
|
||||
// which is used for unit testing cases only.
|
||||
// The optional parameter `names` specifies the sub-folders/sub-files,
|
||||
// which will be joined with current system separator and returned with the path.
|
||||
func DataPath(names ...string) string {
|
||||
_, path, _ := gdebug.CallerWithFilter([]string{pathFilterKey})
|
||||
path = filepath.Dir(path) + string(filepath.Separator) + "testdata"
|
||||
for _, name := range names {
|
||||
path += string(filepath.Separator) + name
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// DataContent retrieves and returns the file content for specified testdata path of current package
|
||||
func DataContent(names ...string) string {
|
||||
path := DataPath(names...)
|
||||
if path != "" {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err == nil {
|
||||
return string(data)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -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.6"
|
||||
const VERSION = "v1.16.8"
|
||||
const AUTHORS = "john<john@goframe.org>"
|
||||
|
||||
Reference in New Issue
Block a user