mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 11:18:50 +08:00
improve gerror for stack information; fix issue in gconv.String for nil *time.Time type
This commit is contained in:
parent
1deb3510f0
commit
382356bc8d
@ -9,6 +9,7 @@ package gerror
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"io"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -22,7 +23,7 @@ type Error struct {
|
||||
}
|
||||
|
||||
const (
|
||||
gFILTER_KEY = "github.com/gogf/gf/"
|
||||
gFILTER_KEY = "/errors/gerror/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -130,6 +131,19 @@ func formatSubStack(st stack, buffer *bytes.Buffer) {
|
||||
if strings.Contains(file, gFILTER_KEY) {
|
||||
continue
|
||||
}
|
||||
if !intlog.IsInGFDevelop() {
|
||||
// Avoid GF stacks if not in GF development.
|
||||
if strings.Contains(file, "github.com/gogf/gf/") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(file, "github.com/gogf/gf@") {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// Avoid stack string like "<autogenerated>"
|
||||
if strings.Contains(file, "<") {
|
||||
continue
|
||||
}
|
||||
if goRootForFilter != "" && len(file) >= len(goRootForFilter) && file[0:len(goRootForFilter)] == goRootForFilter {
|
||||
continue
|
||||
}
|
||||
|
@ -70,3 +70,24 @@ func IsEmpty(value interface{}) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsNil checks whether given <value> is nil.
|
||||
// Note that it's using reflect feature which affects performance a little bit.
|
||||
func IsNil(value interface{}) bool {
|
||||
if value == nil {
|
||||
return true
|
||||
}
|
||||
rv := reflect.ValueOf(value)
|
||||
switch rv.Kind() {
|
||||
case reflect.Chan,
|
||||
reflect.Map,
|
||||
reflect.Slice,
|
||||
reflect.Array,
|
||||
reflect.Func,
|
||||
reflect.Ptr,
|
||||
reflect.Interface,
|
||||
reflect.UnsafePointer:
|
||||
return rv.IsNil()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -31,6 +31,11 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// IsInGFDevelop checks and returns whether current process is in GF development.
|
||||
func IsInGFDevelop() bool {
|
||||
return isInGFDevelop
|
||||
}
|
||||
|
||||
// Print prints <v> with newline using fmt.Println.
|
||||
// The parameter <v> can be multiple variables.
|
||||
func Print(v ...interface{}) {
|
||||
|
@ -22,6 +22,7 @@ func Test_Params_Struct(t *testing.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Name string
|
||||
Time *time.Time
|
||||
Pass1 string `params:"password1"`
|
||||
Pass2 string `params:"password2" gvalid:"passwd1 @required|length:2,20|password3#||密码强度不足"`
|
||||
}
|
||||
|
@ -10,9 +10,12 @@ package gconv
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/empty"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/encoding/gbinary"
|
||||
)
|
||||
@ -149,6 +152,7 @@ func Runes(i interface{}) []rune {
|
||||
}
|
||||
|
||||
// String converts <i> to string.
|
||||
// It's most common used converting function.
|
||||
func String(i interface{}) string {
|
||||
if i == nil {
|
||||
return ""
|
||||
@ -186,7 +190,20 @@ func String(i interface{}) string {
|
||||
return string(value)
|
||||
case []rune:
|
||||
return string(value)
|
||||
case *time.Time:
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
return value.String()
|
||||
case *gtime.Time:
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
return value.String()
|
||||
default:
|
||||
if empty.IsNil(value) {
|
||||
return ""
|
||||
}
|
||||
if f, ok := value.(apiString); ok {
|
||||
// If the variable implements the String() interface,
|
||||
// then use that interface to perform the conversion
|
||||
|
Loading…
x
Reference in New Issue
Block a user