refactor: switch to new ! syntax

main
Jef Roosens 2022-11-01 20:58:27 +01:00
parent f6d5c17cc0
commit edd9e3fde9
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 6 additions and 6 deletions

View File

@ -30,7 +30,7 @@ struct Response {
results []Package results []Package
} }
fn (c Client) request(params map[string][]string) ?[]Package { fn (c Client) request(params map[string][]string) ![]Package {
mut param_strings := []string{} mut param_strings := []string{}
for k, v in params { for k, v in params {
@ -39,14 +39,14 @@ fn (c Client) request(params map[string][]string) ?[]Package {
url := '$c.url?${param_strings.join('&')}' url := '$c.url?${param_strings.join('&')}'
res := http.get(url)? res := http.get(url)!
if res.status_code < 200 || res.status_code >= 300 { if res.status_code < 200 || res.status_code >= 300 {
// temporary // temporary
return error('error') return error('error')
} }
data := json.decode(Response, res.body)? data := json.decode(Response, res.body)!
if data.@type == 'error' { if data.@type == 'error' {
return error('Server responded with an error: $data.error') return error('Server responded with an error: $data.error')
@ -55,7 +55,7 @@ fn (c Client) request(params map[string][]string) ?[]Package {
return data.results return data.results
} }
pub fn (c Client) search_by(arg string, st SearchType) ?[]Package { pub fn (c Client) search_by(arg string, st SearchType) ![]Package {
params := { params := {
'v': ['5'] 'v': ['5']
'type': ['search'] 'type': ['search']
@ -67,11 +67,11 @@ pub fn (c Client) search_by(arg string, st SearchType) ?[]Package {
} }
// search performs a search by name_desc. // search performs a search by name_desc.
pub fn (c Client) search(arg string) ?[]Package { pub fn (c Client) search(arg string) ![]Package {
return c.search_by(arg, .name_desc) return c.search_by(arg, .name_desc)
} }
pub fn (c Client) info(pkgs []string) ?[]Package { pub fn (c Client) info(pkgs []string) ![]Package {
params := { params := {
'v': ['5'] 'v': ['5']
'type': ['info'] 'type': ['info']