-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (65 loc) · 2.18 KB
/
main.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/piprate/json-gold/ld"
)
func jsonld() {
proc := ld.NewJsonLdProcessor()
options := ld.NewJsonLdOptions("")
// expanding remote document
expanded, err := proc.Expand("/home/fjammes/src/mdformatter/micro-services.json", options)
if err != nil {
log.Println("Error when expanding JSON-LD document:", err)
return
}
ld.PrintDocument("JSON-LD expansion succeeded", expanded)
doc := map[string]interface{}{
"@context": "http://schema.org/",
"@type": "Person",
"name": "Jane Doe",
"jobTitle": "Professor",
"telephone": "(425) 123-4567",
"url": "http://www.janedoe.com",
}
expanded, err = proc.Expand(doc, options)
if err != nil {
panic(err)
}
ld.PrintDocument("JSON-LD expansion succeeded", expanded)
}
func main() {
var jsonFilename string
flag.StringVar(&jsonFilename, "json", "", "path to json-ld file")
// md := flag.String("md", "", "path to md file")
flag.Parse()
// Open our jsonFile
jsonFile, err := os.Open(jsonFilename)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Printf("Successfully Opened %s\n", jsonFilename)
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var result map[string]interface{}
json.Unmarshal([]byte(byteValue), &result)
data := result["data"]
jsonlist := data.([]interface{})
product := jsonlist[0].(map[string]interface{})
reviews := product["review"].([]interface{})
// <div class="Stars" style="--rating: 5;" aria-label="La note de ce produit est 5 sur 5.">Denis C. de Hewlett-Packard: Formateur très professionnel et très compétent sur le sujet K8s.</div>
for _, r := range reviews {
review := r.(map[string]interface{})
reviewRating := review["reviewRating"].(map[string]interface{})
author := review["author"].(map[string]interface{})
fmt.Printf("<div class=\"Stars\" style=\"--rating: 5;\" aria-label=\"La note de ce produit est %v sur 5.\">", reviewRating["ratingValue"])
fmt.Printf("%s, %s</div>\n", author["name"], review["reviewBody"])
// fmt.Println(review["datePublished"])
}
}