2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-03 05:12:01 +08:00

Add String and MarshalJSON methods to Payload type

This commit is contained in:
Ken Hibino
2020-09-19 20:52:21 -07:00
parent a2d4ead989
commit fadcae76d6
3 changed files with 43 additions and 0 deletions

View File

@@ -44,6 +44,16 @@ func toInt(v interface{}) (int, error) {
}
}
// String returns a string representation of payload data.
func (p Payload) String() string {
return fmt.Sprint(p.data)
}
// MarshalJSON returns the JSON encoding of payload data.
func (p Payload) MarshalJSON() ([]byte, error) {
return json.Marshal(p.data)
}
// GetString returns a string value if a string type is associated with
// the key, otherwise reports an error.
func (p Payload) GetString(key string) (string, error) {