From b4ea20d1d39b51f1cfc3d4719e75284bbe9deb91 Mon Sep 17 00:00:00 2001 From: lbenedar Date: Tue, 10 Mar 2026 15:50:42 +0300 Subject: [PATCH] ch3.5 --- internal/data/movies.go | 2 +- internal/data/runtime.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 internal/data/runtime.go diff --git a/internal/data/movies.go b/internal/data/movies.go index f1b042c..040175c 100644 --- a/internal/data/movies.go +++ b/internal/data/movies.go @@ -7,7 +7,7 @@ type Movie struct { CreatedAt time.Time `json:"-"` Title string `json:"title"` Year int32 `json:"year,omitempty"` - Runtime int32 `json:"runtime,omitempty,string"` + Runtime Runtime `json:"runtime,omitempty"` Genres []string `json:"genres,omitempty"` Version int32 `json:"version"` } diff --git a/internal/data/runtime.go b/internal/data/runtime.go new file mode 100644 index 0000000..85295bb --- /dev/null +++ b/internal/data/runtime.go @@ -0,0 +1,15 @@ +package data + +import ( + "fmt" + "strconv" +) + +type Runtime int32 + +func (r Runtime) MarshalJSON() ([]byte, error) { + jsonValue := fmt.Sprintf("%d mins", r) + + quotedJSONValue := strconv.Quote(jsonValue) + return []byte(quotedJSONValue), nil +}