-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (39 loc) · 1.23 KB
/
main.go
File metadata and controls
52 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"encoding/json"
"fmt"
"os"
"time"
)
type Info struct {
ID int `json:"id"`
Title string `json:"title"`
Price int `json:"price"`
Quantity int `json:"quantity"`
Total int `json:"total"`
DiscountPercentage float64 `json:"discountPercentage"`
DiscountedPrice int `json:"discountedPrice"`
Thumbnail string `json:"thumbnail"`
CreatedAt time.Time `json:"created_at"`
}
func main() {
f, err := os.Open("file.json")
if err != nil {
panic(err)
}
defer f.Close()
var info Info
err = json.NewDecoder(f).Decode(&info)
if err != nil {
panic(err)
}
fmt.Println("ID:", info.ID)
fmt.Println("Title:", info.Title)
fmt.Println("Price:", info.Price)
fmt.Println("Quantity:", info.Quantity)
fmt.Println("Total:", info.Total)
fmt.Println("DiscountPercentage:", info.DiscountPercentage)
fmt.Println("DiscountedPrice:", info.DiscountedPrice)
fmt.Println("Thumbnail:", info.Thumbnail)
fmt.Println("CreatedAt:", info.CreatedAt.Format("02/01 15:04:05 2006"))
}