improve gtcp

This commit is contained in:
John
2019-06-03 23:53:59 +08:00
parent 6ac437a3a5
commit 00a8ef63b6
13 changed files with 138 additions and 95 deletions

View File

@ -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)