summaryrefslogtreecommitdiff
path: root/ytparser/ytparser.go
diff options
context:
space:
mode:
Diffstat (limited to 'ytparser/ytparser.go')
-rw-r--r--ytparser/ytparser.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/ytparser/ytparser.go b/ytparser/ytparser.go
index ec89406..57c2a31 100644
--- a/ytparser/ytparser.go
+++ b/ytparser/ytparser.go
@@ -37,7 +37,7 @@ func (item Item) String() string {
return fmt.Sprintf("id: %s, title: %s, url: %s, thumb: %s", item.Id, item.Title, item.Url, item.Thumb)
}
-func parsejson(data string) []Item {
+func parsejson(data string) ([]Item, error) {
//fmt.Println(data)
dec := json.NewDecoder(strings.NewReader(data))
@@ -54,7 +54,7 @@ func parsejson(data string) []Item {
if err == io.EOF {
break
} else if err != nil {
- panic(err)
+ return nil, err
}
switch t := tok.(type) {
@@ -122,7 +122,7 @@ func parsejson(data string) []Item {
default:
}
}
- return items
+ return items, nil
//fmt.Println(names)
}
@@ -154,10 +154,10 @@ func request(query string, page int) (string, error) {
return string(startData), nil
}
-func Search(query string, page int) []Item {
+func Search(query string, page int) ([]Item, error) {
data, err := request(query, page)
if err != nil {
- panic(err)
+ return nil, err
}
return parsejson(data)
}