Use Runtime type instead of int32 in our Movie struct.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 54s
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 54s
This commit is contained in:
@@ -12,7 +12,10 @@ type Movie struct {
|
|||||||
CreatedAt time.Time `json:"-"`
|
CreatedAt time.Time `json:"-"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Year int32 `json:"year,omitempty"`
|
Year int32 `json:"year,omitempty"`
|
||||||
Runtime int32 `json:"runtime,omitempty,string"`
|
/*
|
||||||
|
Use the Runtime type instead of int32. Note that the omitempty directive will still work on this: if the Runtime field has the underlying value 0, then it will be considered empty and omitted -- and the MarshalJSON() method we just made won't be called at all.
|
||||||
|
*/
|
||||||
|
Runtime Runtime `json:"runtime,omitempty,string"`
|
||||||
Genres []string `json:"genres,omitempty"`
|
Genres []string `json:"genres,omitempty"`
|
||||||
Version int32 `json:"version"`
|
Version int32 `json:"version"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ type Runtime int32
|
|||||||
|
|
||||||
// MarshalJSON
|
// MarshalJSON
|
||||||
/*
|
/*
|
||||||
Implement a MarshalJSON() method on the Runtime type so that it satisfies
|
Implement a MarshalJSON() method on the Runtime type so that it satisfies the json.Marshaler interface. This should return the JSON-encoded value for the movie runtime (in our case, it will return string in the format "<runtime> mins").
|
||||||
the json.Marshaler interface. This should return the JSON-encoded value
|
|
||||||
for the movie runtime (in our case, it will return string in the format
|
|
||||||
"<runtime> mins").
|
|
||||||
*/
|
*/
|
||||||
func (r Runtime) MarshalJSON() ([]byte, error) {
|
func (r Runtime) MarshalJSON() ([]byte, error) {
|
||||||
// Generate a string containing the movie runtime in the required format.
|
// Generate a string containing the movie runtime in the required format.
|
||||||
|
|||||||
Reference in New Issue
Block a user