-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEC-2159] - add generic json printer to help format customtypes in p…
…rotos (#702) * add generic json printer to help format customtypes in protos * remove unreachable check for nil jsonData
- Loading branch information
1 parent
71529ce
commit e47a416
Showing
2 changed files
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lib | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// MaybeGetStructJsonString returns the json representation of a struct, or a formatted string using | ||
// %+v if the json conversion encounters an error. | ||
func MaybeGetJsonString(i interface{}) string { | ||
jsonData, err := json.Marshal(i) | ||
if err != nil { | ||
return fmt.Sprintf("%+v", i) | ||
} | ||
|
||
return string(jsonData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters