Pleased vfmt & vet
ci/woodpecker/push/arch unknown status Details
ci/woodpecker/push/deploy unknown status Details
ci/woodpecker/push/docker unknown status Details
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details

pull/114/head
Jef Roosens 2022-04-07 11:58:05 +02:00
parent 7eb0aa76e1
commit b31b4cbd7a
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 13 additions and 8 deletions

View File

@ -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<map[string]git.GitRepo>, res.text) ?
data := json.decode(response.Response<map[string]GitRepo>, 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)
}

View File

@ -5,6 +5,8 @@ pub struct Response<T> {
data T
}
// new_response constructs a new Response<String> object with the given message
// & an empty data field.
pub fn new_response(message string) Response<string> {
return Response<string>{
message: message
@ -12,6 +14,8 @@ pub fn new_response(message string) Response<string> {
}
}
// new_data_response<T> constructs a new Response<T> object with the given data
// & an empty message field.
pub fn new_data_response<T>(data T) Response<T> {
return Response<T>{
message: ''
@ -19,6 +23,8 @@ pub fn new_data_response<T>(data T) Response<T> {
}
}
// new_full_response<T> constructs a new Response<T> object with the given
// message & data.
pub fn new_full_response<T>(message string, data T) Response<T> {
return Response<T>{
message: message

View File

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

View File

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