summaryrefslogtreecommitdiff
path: root/ytparser
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst92@gmail.com>2020-10-15 10:34:36 +0200
committerJulian Hurst <julian.hurst92@gmail.com>2020-10-15 10:34:36 +0200
commit8539126144ae6d94a24525f125e54b372b22f821 (patch)
treef4ef2cb3a39c569690fb0ba24f3e32128a8d33b3 /ytparser
parente670f9d19f658055e169b6d7c3ae57ddc11c3eee (diff)
downloadgrimtube-8539126144ae6d94a24525f125e54b372b22f821.tar.gz
[ytparser]: return errors
Diffstat (limited to 'ytparser')
-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)
}