Jamie Hannaford | 6abf928 | 2014-09-24 10:54:13 +0200 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | // MaybeString takes a string that might be a zero-value, and either returns a |
| 4 | // pointer to its address or a nil value (i.e. empty pointer). This is useful |
| 5 | // for converting zero values in options structs when the end-user hasn't |
| 6 | // defined values. Those zero values need to be nil in order for the JSON |
| 7 | // serialization to ignore them. |
| 8 | func MaybeString(original string) *string { |
| 9 | if original != "" { |
| 10 | return &original |
| 11 | } |
| 12 | return nil |
| 13 | } |