mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
http: use optionals (finally)
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
import http
|
||||
|
||||
fn main() {
|
||||
html := http.get('https://news.ycombinator.com') or {
|
||||
println('Failed fetching from URL')
|
||||
return
|
||||
}
|
||||
html := http.get_text('https://news.ycombinator.com')
|
||||
mut pos := 0
|
||||
for {
|
||||
pos = html.index_after('https://', pos + 1)
|
||||
|
||||
@@ -37,7 +37,7 @@ fn (f mut Fetcher) fetch() {
|
||||
println('failed to fetch data from /v0/item/${id}.json')
|
||||
exit(1)
|
||||
}
|
||||
story := json.decode(Story, resp) or {
|
||||
story := json.decode(Story, resp.text) or {
|
||||
println('failed to decode a story')
|
||||
exit(1)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ fn main() {
|
||||
println('failed to fetch data from /v0/topstories.json')
|
||||
return
|
||||
}
|
||||
mut ids := json.decode([]int, resp) or {
|
||||
mut ids := json.decode([]int, resp.text) or {
|
||||
println('failed to decode topstories.json')
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user