improve gconv to support struct field of interface{} conversion

This commit is contained in:
John
2019-08-01 19:53:28 +08:00
parent 9e96a30ea2
commit e622f6aff2
7 changed files with 478 additions and 35 deletions

View File

@ -9,8 +9,6 @@ package gerror
import (
"fmt"
"github.com/gogf/gf/util/gconv"
)
type ApiStack interface {
@ -21,16 +19,8 @@ type ApiCause interface {
Cause() error
}
// New returns an error that formats as the given value.
func New(value interface{}) error {
if value == nil {
return nil
}
return NewText(gconv.String(value))
}
// NewText returns an error that formats as the given text.
func NewText(text string) error {
// New returns an error that formats as the given text.
func New(text string) error {
if text == "" {
return nil
}

View File

@ -25,7 +25,7 @@ func nilError() error {
func Test_Nil(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gerror.New(interfaceNil()), nil)
gtest.Assert(gerror.New(""), nil)
gtest.Assert(gerror.Wrap(nilError(), "test"), nil)
})
}