mirror of
https://gitee.com/johng/gf
synced 2026-07-04 21:03:13 +08:00
improve gtcp
This commit is contained in:
@ -20,6 +20,11 @@ type apiString interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// Type assert api for Error().
|
||||
type apiError interface {
|
||||
Error() string
|
||||
}
|
||||
|
||||
var (
|
||||
// Empty strings.
|
||||
emptyStringMap = map[string]struct{}{
|
||||
@ -143,6 +148,10 @@ func String(i interface{}) string {
|
||||
// If the variable implements the String() interface,
|
||||
// then use that interface to perform the conversion
|
||||
return f.String()
|
||||
} else if f, ok := value.(apiError); ok {
|
||||
// If the variable implements the Error() interface,
|
||||
// then use that interface to perform the conversion
|
||||
return f.Error()
|
||||
} else {
|
||||
// Finally we use json.Marshal to convert.
|
||||
jsonContent, _ := json.Marshal(value)
|
||||
|
||||
Reference in New Issue
Block a user