1
0
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:
Alexander Medvednikov
2019-07-31 22:10:28 +02:00
parent 15f1169102
commit aac8503d83
4 changed files with 17 additions and 30 deletions

View File

@@ -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)

View File

@@ -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
}