summaryrefslogtreecommitdiff
path: root/storageinfo.go
diff options
context:
space:
mode:
Diffstat (limited to 'storageinfo.go')
-rw-r--r--storageinfo.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/storageinfo.go b/storageinfo.go
index 4e1e9b0..ea08bc6 100644
--- a/storageinfo.go
+++ b/storageinfo.go
@@ -6,20 +6,20 @@ import (
"strconv"
)
-// MarshalJSON custom marshals the StorageInfo struct to JSON
-func (s StorageInfo) MarshalJSON() ([]byte, error) {
+// MarshalJSON custom marshals the WhatInfo struct to JSON
+func (s WhatInfo) MarshalJSON() ([]byte, error) {
capacityStr := fmt.Sprintf("%d GB", s.Capacity)
return json.Marshal(map[string]string{
"capacity": capacityStr,
})
}
-func (s StorageInfo) FormatJSON() string {
+func (s WhatInfo) FormatJSON() string {
return fmt.Sprintf("\"capacity\": \"%d GB\"", s.Capacity)
}
-// UnmarshalJSON custom unmarshals JSON into the StorageInfo struct
-func (s *StorageInfo) UnmarshalJSON(data []byte) error {
+// UnmarshalJSON custom unmarshals JSON into the WhatInfo struct
+func (s *WhatInfo) UnmarshalJSON(data []byte) error {
var raw map[string]string
if err := json.Unmarshal(data, &raw); err != nil {
return err
@@ -39,14 +39,14 @@ func (s *StorageInfo) UnmarshalJSON(data []byte) error {
/*
func main() {
- info := StorageInfo{Capacity: 64}
+ info := WhatInfo{Capacity: 64}
// Marshaling to JSON
jsonData, _ := json.Marshal(info)
fmt.Println(string(jsonData)) // Output: {"capacity":"64 GB"}
// Unmarshaling back to Go struct
- var newInfo StorageInfo
+ var newInfo WhatInfo
_ = json.Unmarshal(jsonData, &newInfo)
fmt.Println(newInfo.Capacity) // Output: 64
}