OMDB_api
This commit is contained in:
parent
75ffdefb4a
commit
48f498a1dd
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"text/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
@ -24,9 +25,20 @@ type Ratings struct {
|
||||||
Value string `json:"Value"`
|
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) {
|
func Search(s string) (SearchRes,error) {
|
||||||
resp,err := http.Get(URL + "?apikey=" + KEY + "&t=" + s)
|
resp,err := http.Get(URL + "?apikey=" + KEY + "&t=" + s)
|
||||||
|
|
@ -45,6 +57,9 @@ func Search(s string) (SearchRes,error) {
|
||||||
func main() {
|
func main() {
|
||||||
arg := os.Args[1]
|
arg := os.Args[1]
|
||||||
// fmt.Println(arg)
|
// 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user