From c444630d1e88db3daee413a014b32bd868bfba0e Mon Sep 17 00:00:00 2001 From: John Date: Sun, 8 Mar 2020 11:56:19 +0800 Subject: [PATCH] add workaround for package gdb for json infinite loop bug of Golang version < v1.14 --- database/gdb/gdb_core.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/database/gdb/gdb_core.go b/database/gdb/gdb_core.go index 7ac95a739..32eba81a0 100644 --- a/database/gdb/gdb_core.go +++ b/database/gdb/gdb_core.go @@ -699,6 +699,15 @@ func (c *Core) rowsToResult(rows *sql.Rows) (Result, error) { return records, nil } +// MarshalJSON implements the interface MarshalJSON for json.Marshal. +// It just returns the pointer address. +// +// Note that this interface implements mainly for workaround for a json infinite loop bug +// of Golang version < v1.14. +func (c *Core) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%+v`, c)), nil +} + // writeSqlToLogger outputs the sql object to logger. // It is enabled when configuration "debug" is true. func (c *Core) writeSqlToLogger(v *Sql) {