diff --git a/book_with_bridge/OMDBAPI/main.go b/book_with_bridge/OMDBAPI/main.go index 7e72c66..ee117e3 100644 --- a/book_with_bridge/OMDBAPI/main.go +++ b/book_with_bridge/OMDBAPI/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "text/template" "net/http" "os" ) @@ -24,9 +25,20 @@ type Ratings struct { Value string `json:"Value"` } -type Plug any +const templ = ` +======================= +Title: {{.Title}} +Year: {{.Year}} +Genre: {{.Genre}} +Rating: +{{range .Ratings}} + Source: {{.Source}} + Rating: {{.Value}} +{{end}} +======================= +` -type PlugStruct struct {} +var report = template.Must(template.New("MovieReport").Parse(templ)) func Search(s string) (SearchRes,error) { resp,err := http.Get(URL + "?apikey=" + KEY + "&t=" + s) @@ -45,6 +57,9 @@ func Search(s string) (SearchRes,error) { func main() { arg := os.Args[1] // fmt.Println(arg) - fmt.Println(Search(arg)) + res,_ := Search(arg) + if err := report.Execute(os.Stdout,res); err != nil { + fmt.Printf("Cannot show report ",err) + } }