From b31b4cbd7a9fc1b64061c253e4260f66d56e0430 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 7 Apr 2022 11:58:05 +0200 Subject: [PATCH] Pleased vfmt & vet --- src/git/cli.v | 11 +++++------ src/response.v | 6 ++++++ src/server/git.v | 2 +- src/server/routes.v | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/git/cli.v b/src/git/cli.v index c4d4d80..7e41b1c 100644 --- a/src/git/cli.v +++ b/src/git/cli.v @@ -4,7 +4,6 @@ import cli import env import net.http import json -import git import response struct Config { @@ -56,12 +55,12 @@ pub fn cmd() cli.Command { } } -fn get_repos(conf Config) ?map[string]git.GitRepo { +fn get_repos(conf Config) ?map[string]GitRepo { mut req := http.new_request(http.Method.get, '$conf.address/api/repos', '') ? req.add_custom_header('X-API-Key', conf.api_key) ? res := req.do() ? - data := json.decode(response.Response, res.text) ? + data := json.decode(response.Response, res.text) ? return data.data } @@ -70,7 +69,7 @@ fn list(conf Config) ? { repos := get_repos(conf) ? for id, details in repos { - println("${id[..8]}\t$details.url\t$details.branch\t$details.arch") + println('${id[..8]}\t$details.url\t$details.branch\t$details.arch') } } @@ -96,12 +95,12 @@ fn remove(conf Config, id_prefix string) ? { } if to_remove.len == 0 { - eprintln("No repo found for given prefix.") + eprintln('No repo found for given prefix.') exit(1) } if to_remove.len > 1 { - eprintln("Multiple repos found for given prefix.") + eprintln('Multiple repos found for given prefix.') exit(1) } diff --git a/src/response.v b/src/response.v index 1618fcf..7e268b1 100644 --- a/src/response.v +++ b/src/response.v @@ -5,6 +5,8 @@ pub struct Response { data T } +// new_response constructs a new Response object with the given message +// & an empty data field. pub fn new_response(message string) Response { return Response{ message: message @@ -12,6 +14,8 @@ pub fn new_response(message string) Response { } } +// new_data_response constructs a new Response object with the given data +// & an empty message field. pub fn new_data_response(data T) Response { return Response{ message: '' @@ -19,6 +23,8 @@ pub fn new_data_response(data T) Response { } } +// new_full_response constructs a new Response object with the given +// message & data. pub fn new_full_response(message string, data T) Response { return Response{ message: message diff --git a/src/server/git.v b/src/server/git.v index 359d6ce..2a682d8 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -4,7 +4,7 @@ import web import git import net.http import rand -import response { new_response, new_data_response } +import response { new_data_response, new_response } const repos_file = 'repos.json' diff --git a/src/server/routes.v b/src/server/routes.v index 71da02a..07279cb 100644 --- a/src/server/routes.v +++ b/src/server/routes.v @@ -7,7 +7,7 @@ import time import rand import util import net.http -import response { new_response, new_data_response } +import response { new_response } // healthcheck just returns a string, but can be used to quickly check if the // server is still responsive.