chore: ran v fmt for v 0.3.3 changes

Jef Roosens 2023-02-08 11:00:17 +01:00
parent e10b450abd
commit b3a119f221
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
37 changed files with 179 additions and 175 deletions

View File

@ -23,7 +23,7 @@ pub fn cmd() cli.Command {
description: 'Start an agent daemon.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
agent(conf)!
}

View File

@ -51,7 +51,7 @@ pub fn (mut d AgentDaemon) run() {
for {
if sleep_time > 0 {
d.ldebug('Sleeping for $sleep_time')
d.ldebug('Sleeping for ${sleep_time}')
time.sleep(sleep_time)
}
@ -80,14 +80,14 @@ pub fn (mut d AgentDaemon) run() {
d.ldebug('Polling for new jobs')
new_configs := d.client.poll_jobs(d.conf.arch, finished + empty) or {
d.lerror('Failed to poll jobs: $err.msg()')
d.lerror('Failed to poll jobs: ${err.msg()}')
// TODO pick a better delay here
sleep_time = 5 * time.second
continue
}
d.ldebug('Received $new_configs.len jobs')
d.ldebug('Received ${new_configs.len} jobs')
last_poll_time = time.now()
@ -95,7 +95,7 @@ pub fn (mut d AgentDaemon) run() {
// Make sure a recent build base image is available for
// building the config
if !d.images.up_to_date(config.base_image) {
d.linfo('Building builder image from base image $config.base_image')
d.linfo('Building builder image from base image ${config.base_image}')
// TODO handle this better than to just skip the config
d.images.refresh_image(config.base_image) or {
@ -154,7 +154,7 @@ fn (mut d AgentDaemon) start_build(config BuildConfig) bool {
stdatomic.store_u64(&d.atomics[i], agent.build_running)
d.builds[i] = config
go d.run_build(i, config)
spawn d.run_build(i, config)
return true
}
@ -165,7 +165,7 @@ fn (mut d AgentDaemon) start_build(config BuildConfig) bool {
// run_build actually starts the build process for a given target.
fn (mut d AgentDaemon) run_build(build_index int, config BuildConfig) {
d.linfo('started build: $config')
d.linfo('started build: ${config}')
// 0 means success, 1 means failure
mut status := 0
@ -176,21 +176,21 @@ fn (mut d AgentDaemon) run_build(build_index int, config BuildConfig) {
}
res := build.build_config(d.client.address, d.client.api_key, new_config) or {
d.ldebug('build_config error: $err.msg()')
d.ldebug('build_config error: ${err.msg()}')
status = 1
build.BuildResult{}
}
if status == 0 {
d.linfo('Uploading build logs for $config')
d.linfo('Uploading build logs for ${config}')
// TODO use the arch value here
build_arch := os.uname().machine
d.client.add_build_log(config.target_id, res.start_time, res.end_time, build_arch,
res.exit_code, res.logs) or { d.lerror('Failed to upload logs for $config') }
res.exit_code, res.logs) or { d.lerror('Failed to upload logs for ${config}') }
} else {
d.lwarn('an error occurred during build: $config')
d.lwarn('an error occurred during build: ${config}')
}
stdatomic.store_u64(&d.atomics[build_index], agent.build_done)

View File

@ -71,7 +71,7 @@ pub fn (mut m ImageManager) up_to_date(base_image string) bool {
fn (mut m ImageManager) refresh_image(base_image string) ! {
// TODO use better image tags for built images
new_image := build.create_build_image(base_image) or {
return error('Failed to build builder image from base image $base_image')
return error('Failed to build builder image from base image ${base_image}')
}
m.images[base_image] << new_image

View File

@ -45,7 +45,7 @@ pub fn create_build_image(base_image string) !string {
c := docker.NewContainer{
image: base_image
env: ['BUILD_SCRIPT=$cmds_str']
env: ['BUILD_SCRIPT=${cmds_str}']
entrypoint: ['/bin/sh', '-c']
cmd: ['echo \$BUILD_SCRIPT | base64 -d | /bin/sh -e']
}
@ -118,10 +118,10 @@ pub fn build_config(address string, api_key string, config BuildConfig) !BuildRe
base64_script := base64.encode_str(build_script)
c := docker.NewContainer{
image: '$config.base_image'
image: '${config.base_image}'
env: [
'BUILD_SCRIPT=$base64_script',
'API_KEY=$api_key',
'BUILD_SCRIPT=${base64_script}',
'API_KEY=${api_key}',
// `archlinux:base-devel` does not correctly set the path variable,
// causing certain builds to fail. This fixes it.
'PATH=${build.path_dirs.join(':')}',

View File

@ -36,7 +36,7 @@ pub struct BuildJobQueue {
mut:
mutex shared util.Dummy
// For each architecture, a priority queue is tracked
queues map[string]MinHeap<BuildJob>
queues map[string]MinHeap[BuildJob]
// When a target is removed from the server or edited, its previous build
// configs will be invalid. This map allows for those to be simply skipped
// by ignoring any build configs created before this timestamp.
@ -74,7 +74,7 @@ pub struct InsertConfig {
pub fn (mut q BuildJobQueue) insert(input InsertConfig) ! {
lock q.mutex {
if input.arch !in q.queues {
q.queues[input.arch] = MinHeap<BuildJob>{}
q.queues[input.arch] = MinHeap[BuildJob]{}
}
mut job := BuildJob{
@ -86,7 +86,7 @@ pub fn (mut q BuildJobQueue) insert(input InsertConfig) ! {
if !input.now {
ce := if input.target.schedule != '' {
cron.parse_expression(input.target.schedule) or {
return error("Error while parsing cron expression '$input.target.schedule' (id $input.target.id): $err.msg()")
return error("Error while parsing cron expression '${input.target.schedule}' (id ${input.target.id}): ${err.msg()}")
}
} else {
q.default_schedule

View File

@ -24,12 +24,12 @@ pub fn echo_commands(cmds []string) []string {
// create_build_script generates a shell script that builds a given Target.
fn create_build_script(address string, config BuildConfig, build_arch string) string {
repo_url := '$address/$config.repo'
repo_url := '${address}/${config.repo}'
mut commands := [
// This will later be replaced by a proper setting for changing the
// mirrorlist
"echo -e '[$config.repo]\\nServer = $address/\$repo/\$arch\\nSigLevel = Optional' >> /etc/pacman.conf"
"echo -e '[${config.repo}]\\nServer = ${address}/\$repo/\$arch\\nSigLevel = Optional' >> /etc/pacman.conf"
// We need to update the package list of the repo we just added above.
// This should however not pull in a lot of packages as long as the
// builder image is rebuilt frequently.
@ -42,18 +42,18 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
'git' {
if config.branch == '' {
[
"git clone --single-branch --depth 1 '$config.url' repo",
"git clone --single-branch --depth 1 '${config.url}' repo",
]
} else {
[
"git clone --single-branch --depth 1 --branch $config.branch '$config.url' repo",
"git clone --single-branch --depth 1 --branch ${config.branch} '${config.url}' repo",
]
}
}
'url' {
[
'mkdir repo',
"curl -o repo/PKGBUILD -L '$config.url'",
"curl -o repo/PKGBUILD -L '${config.url}'",
]
}
else {
@ -62,7 +62,7 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
}
commands << if config.path != '' {
"cd 'repo/$config.path'"
"cd 'repo/${config.path}'"
} else {
'cd repo'
}
@ -76,7 +76,7 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
// The build container checks whether the package is already present on
// the server.
commands << [
'curl -s --head --fail $repo_url/$build_arch/\$pkgname-\$pkgver-\$pkgrel && exit 0',
'curl -s --head --fail ${repo_url}/${build_arch}/\$pkgname-\$pkgver-\$pkgrel && exit 0',
// If the above curl command succeeds, we don't need to rebuild the
// package. However, because we're in a su shell, the exit command will
// drop us back into the root shell. Therefore, we must check whether
@ -86,7 +86,7 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
}
commands << [
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $repo_url/publish; done',
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" ${repo_url}/publish; done',
]
return echo_commands(commands).join('\n')

View File

@ -22,7 +22,7 @@ pub fn new(address string, api_key string) Client {
// send_request_raw sends an HTTP request, returning the http.Response object.
// It encodes the params so that they're safe to pass as HTTP query parameters.
fn (c &Client) send_request_raw(method Method, url string, params map[string]string, body string) !http.Response {
mut full_url := '$c.address$url'
mut full_url := '${c.address}${url}'
if params.len > 0 {
mut params_escaped := map[string]string{}
@ -33,9 +33,9 @@ fn (c &Client) send_request_raw(method Method, url string, params map[string]str
params_escaped[k] = urllib.query_escape(v)
}
params_str := params_escaped.keys().map('$it=${params_escaped[it]}').join('&')
params_str := params_escaped.keys().map('${it}=${params_escaped[it]}').join('&')
full_url = '$full_url?$params_str'
full_url = '${full_url}?${params_str}'
}
// Looking at the source code, this function doesn't actually fail, so I'm
@ -49,13 +49,13 @@ fn (c &Client) send_request_raw(method Method, url string, params map[string]str
}
// send_request<T> just calls send_request_with_body<T> with an empty body.
fn (c &Client) send_request<T>(method Method, url string, params map[string]string) !Response<T> {
return c.send_request_with_body<T>(method, url, params, '')
fn (c &Client) send_request[T](method Method, url string, params map[string]string) !Response[T] {
return c.send_request_with_body[T](method, url, params, '')
}
// send_request_with_body<T> calls send_request_raw_response & parses its
// output as a Response<T> object.
fn (c &Client) send_request_with_body<T>(method Method, url string, params map[string]string, body string) !Response<T> {
fn (c &Client) send_request_with_body[T](method Method, url string, params map[string]string, body string) !Response[T] {
res := c.send_request_raw(method, url, params, body)!
status := res.status()
@ -64,12 +64,12 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
if status.is_error() {
// A non-successful status call will have an empty body
if res.body == '' {
return error('Error $res.status_code ($status.str()): (empty response)')
return error('Error ${res.status_code} (${status.str()}): (empty response)')
}
data := json.decode(Response<string>, res.body)!
data := json.decode(Response[string], res.body)!
return error('Status $res.status_code ($status.str()): $data.message')
return error('Status ${res.status_code} (${status.str()}): ${data.message}')
}
// Just return an empty successful response
@ -77,7 +77,7 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
return new_data_response(T{})
}
data := json.decode(Response<T>, res.body)!
data := json.decode(Response[T], res.body)!
return data
}

View File

@ -4,7 +4,7 @@ import models { BuildConfig }
// poll_jobs requests a list of new build jobs from the server.
pub fn (c &Client) poll_jobs(arch string, max int) ![]BuildConfig {
data := c.send_request<[]BuildConfig>(.get, '/api/v1/jobs/poll', {
data := c.send_request[[]BuildConfig](.get, '/api/v1/jobs/poll', {
'arch': arch
'max': max.str()
})!
@ -15,7 +15,7 @@ pub fn (c &Client) poll_jobs(arch string, max int) ![]BuildConfig {
// queue_job adds a new one-time build job for the given target to the job
// queue.
pub fn (c &Client) queue_job(target_id int, arch string, force bool) ! {
c.send_request<string>(.post, '/api/v1/jobs/queue', {
c.send_request[string](.post, '/api/v1/jobs/queue', {
'target': target_id.str()
'arch': arch
'force': force.str()

View File

@ -7,27 +7,27 @@ import time
// get_build_logs returns all build logs.
pub fn (c &Client) get_build_logs(filter BuildLogFilter) ![]BuildLog {
params := models.params_from(filter)
data := c.send_request<[]BuildLog>(.get, '/api/v1/logs', params)!
data := c.send_request[[]BuildLog](.get, '/api/v1/logs', params)!
return data.data
}
// get_build_log returns a specific build log.
pub fn (c &Client) get_build_log(id int) !BuildLog {
data := c.send_request<BuildLog>(.get, '/api/v1/logs/$id', {})!
data := c.send_request[BuildLog](.get, '/api/v1/logs/${id}', {})!
return data.data
}
// get_build_log_content returns the contents of the build log file.
pub fn (c &Client) get_build_log_content(id int) !string {
data := c.send_request_raw_response(.get, '/api/v1/logs/$id/content', {}, '')!
data := c.send_request_raw_response(.get, '/api/v1/logs/${id}/content', {}, '')!
return data
}
// add_build_log adds a new build log to the server.
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) !Response<int> {
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) !Response[int] {
params := {
'target': target_id.str()
'startTime': start_time.unix_time().str()
@ -36,12 +36,12 @@ pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time t
'exitCode': exit_code.str()
}
data := c.send_request_with_body<int>(.post, '/api/v1/logs', params, content)!
data := c.send_request_with_body[int](.post, '/api/v1/logs', params, content)!
return data
}
// remove_build_log removes the build log with the given id from the server.
pub fn (c &Client) remove_build_log(id int) ! {
c.send_request<string>(.delete, '/api/v1/logs/$id', {})!
c.send_request[string](.delete, '/api/v1/logs/${id}', {})!
}

View File

@ -2,15 +2,15 @@ module client
// remove_repo removes an entire repository.
pub fn (c &Client) remove_repo(repo string) ! {
c.send_request<string>(.delete, '/$repo', {})!
c.send_request[string](.delete, '/${repo}', {})!
}
// remove_arch_repo removes an entire arch-repo.
pub fn (c &Client) remove_arch_repo(repo string, arch string) ! {
c.send_request<string>(.delete, '/$repo/$arch', {})!
c.send_request[string](.delete, '/${repo}/${arch}', {})!
}
// remove_package removes a single package from the given arch-repo.
pub fn (c &Client) remove_package(repo string, arch string, pkgname string) ! {
c.send_request<string>(.delete, '/$repo/$arch/$pkgname', {})!
c.send_request[string](.delete, '/${repo}/${arch}/${pkgname}', {})!
}

View File

@ -5,7 +5,7 @@ import models { Target, TargetFilter }
// get_targets returns a list of targets, given a filter object.
pub fn (c &Client) get_targets(filter TargetFilter) ![]Target {
params := models.params_from(filter)
data := c.send_request<[]Target>(.get, '/api/v1/targets', params)!
data := c.send_request[[]Target](.get, '/api/v1/targets', params)!
return data.data
}
@ -33,7 +33,7 @@ pub fn (c &Client) get_all_targets() ![]Target {
// get_target returns the target for a specific id.
pub fn (c &Client) get_target(id int) !Target {
data := c.send_request<Target>(.get, '/api/v1/targets/$id', {})!
data := c.send_request[Target](.get, '/api/v1/targets/${id}', {})!
return data.data
}
@ -49,15 +49,15 @@ pub struct NewTarget {
// add_target adds a new target to the server.
pub fn (c &Client) add_target(t NewTarget) !int {
params := models.params_from<NewTarget>(t)
data := c.send_request<int>(.post, '/api/v1/targets', params)!
params := models.params_from[NewTarget](t)
data := c.send_request[int](.post, '/api/v1/targets', params)!
return data.data
}
// remove_target removes the target with the given id from the server.
pub fn (c &Client) remove_target(id int) !string {
data := c.send_request<string>(.delete, '/api/v1/targets/$id', {})!
data := c.send_request[string](.delete, '/api/v1/targets/${id}', {})!
return data.data
}
@ -65,7 +65,7 @@ pub fn (c &Client) remove_target(id int) !string {
// patch_target sends a PATCH request to the given target with the params as
// payload.
pub fn (c &Client) patch_target(id int, params map[string]string) !string {
data := c.send_request<string>(.patch, '/api/v1/targets/$id', params)!
data := c.send_request[string](.patch, '/api/v1/targets/${id}', params)!
return data.data
}

View File

@ -36,7 +36,7 @@ pub fn cmd() cli.Command {
required_args: 2
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
c := aur.new()
pkgs := c.info(cmd.args[1..])!
@ -46,14 +46,14 @@ pub fn cmd() cli.Command {
for pkg in pkgs {
vc.add_target(
kind: 'git'
url: 'https://aur.archlinux.org/$pkg.package_base' + '.git'
url: 'https://aur.archlinux.org/${pkg.package_base}' + '.git'
repo: cmd.args[0]
) or {
println('Failed to add $pkg.name: $err.msg()')
println('Failed to add ${pkg.name}: ${err.msg()}')
continue
}
println('Added $pkg.name' + '.')
println('Added ${pkg.name}' + '.')
}
}
},

View File

@ -74,7 +74,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
mut filter := BuildLogFilter{}
@ -156,7 +156,7 @@ pub fn cmd() cli.Command {
description: 'Remove a build log that matches the given id.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
remove(conf, cmd.args[0])!
}
@ -168,7 +168,7 @@ pub fn cmd() cli.Command {
description: 'Show all info for a specific build log.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
id := cmd.args[0].int()
info(conf, id)!
@ -181,7 +181,7 @@ pub fn cmd() cli.Command {
description: 'Output the content of a build log to stdout.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
id := cmd.args[0].int()
content(conf, id)!

View File

@ -28,7 +28,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
if cmd.args.len < 3 {
if !cmd.flags.get_bool('force')! {

View File

@ -54,7 +54,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
mut filter := TargetFilter{}
@ -113,7 +113,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
t := NewTarget{
kind: cmd.flags.get_string('kind')!
@ -135,7 +135,7 @@ pub fn cmd() cli.Command {
description: 'Remove a target that matches the given id.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
remove(conf, cmd.args[0])!
}
@ -147,7 +147,7 @@ pub fn cmd() cli.Command {
description: 'Show detailed information for the target matching the id.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
info(conf, cmd.args[0])!
}
@ -196,7 +196,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
found := cmd.flags.get_all_found()
@ -235,7 +235,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
remote := cmd.flags.get_bool('remote')!
force := cmd.flags.get_bool('force')!
@ -280,7 +280,7 @@ fn add(conf Config, t &NewTarget, raw bool) ! {
if raw {
println(target_id)
} else {
println('Target added with id $target_id')
println('Target added with id ${target_id}')
}
}
@ -296,7 +296,7 @@ fn patch(conf Config, id string, params map[string]string) ! {
// invalid one to the server.
if 'schedule' in params && params['schedule'] != '' {
cron.parse_expression(params['schedule']) or {
return error('Invalid cron expression: $err.msg()')
return error('Invalid cron expression: ${err.msg()}')
}
}

View File

@ -25,7 +25,7 @@ fn test_not_allowed() {
for exp in illegal_expressions {
res = false
parse_expression(exp) or { res = true }
assert res, "'$exp' should produce an error"
assert res, "'${exp}' should produce an error"
}
}

View File

@ -55,7 +55,7 @@ pub fn init(db_path string) !VieterDb {
version_num := i + 1
// vfmt does not like these dots
println('Applying migration $version_num' + '...')
println('Applying migration ${version_num}' + '...')
// The sqlite library seems to not like it when multiple statements are
// passed in a single exec. Therefore, we split them & run them all
@ -64,7 +64,7 @@ pub fn init(db_path string) !VieterDb {
res := conn.exec_none(part)
if res != sqlite.sqlite_done {
return error('An error occurred while applying migration $version_num: SQLite error code $res')
return error('An error occurred while applying migration ${version_num}: SQLite error code ${res}')
}
}
@ -82,7 +82,7 @@ pub fn init(db_path string) !VieterDb {
// row_into<T> converts an sqlite.Row into a given type T by parsing each field
// from a string according to its type.
pub fn row_into<T>(row sqlite.Row) T {
pub fn row_into[T](row sqlite.Row) T {
mut i := 0
mut out := T{}

View File

@ -8,20 +8,20 @@ pub fn (db &VieterDb) get_build_logs(filter BuildLogFilter) []BuildLog {
mut where_parts := []string{}
if filter.target != 0 {
where_parts << 'target_id == $filter.target'
where_parts << 'target_id == ${filter.target}'
}
if filter.before != time.Time{} {
where_parts << 'start_time < $filter.before.unix_time()'
where_parts << 'start_time < ${filter.before.unix_time()}'
}
if filter.after != time.Time{} {
where_parts << 'start_time > $filter.after.unix_time()'
where_parts << 'start_time > ${filter.after.unix_time()}'
}
// NOTE: possible SQL injection
if filter.arch != '' {
where_parts << "arch == '$filter.arch'"
where_parts << "arch == '${filter.arch}'"
}
mut parts := []string{}
@ -30,27 +30,27 @@ pub fn (db &VieterDb) get_build_logs(filter BuildLogFilter) []BuildLog {
if exp[0] == `!` {
code := exp[1..].int()
parts << 'exit_code != $code'
parts << 'exit_code != ${code}'
} else {
code := exp.int()
parts << 'exit_code == $code'
parts << 'exit_code == ${code}'
}
}
if parts.len > 0 {
where_parts << parts.map('($it)').join(' or ')
where_parts << parts.map('(${it})').join(' or ')
}
mut where_str := ''
if where_parts.len > 0 {
where_str = 'where ' + where_parts.map('($it)').join(' and ')
where_str = 'where ' + where_parts.map('(${it})').join(' and ')
}
query := 'select * from BuildLog $where_str limit $filter.limit offset $filter.offset'
query := 'select * from BuildLog ${where_str} limit ${filter.limit} offset ${filter.offset}'
rows, _ := db.conn.exec(query)
res := rows.map(row_into<BuildLog>(it))
res := rows.map(row_into[BuildLog](it))
return res
}

View File

@ -49,13 +49,13 @@ pub fn (db &VieterDb) update_target(target_id int, params map[string]string) {
if field.name in params {
// Any fields that are array types require their own update method
$if field.typ is string {
values << "$field.name = '${params[field.name]}'"
values << "${field.name} = '${params[field.name]}'"
}
}
}
values_str := values.join(', ')
// I think this is actual SQL & not the ORM language
query := 'update Target set $values_str where id == $target_id'
query := 'update Target set ${values_str} where id == ${target_id}'
db.conn.exec_none(query)
}

View File

@ -14,5 +14,5 @@ pub:
// str return a single-line string representation of a build log
pub fn (c BuildConfig) str() string {
return '{ target: $c.target_id, kind: $c.kind, url: $c.url, branch: $c.branch, path: $c.path, repo: $c.repo, base_image: $c.base_image, force: $c.force }'
return '{ target: ${c.target_id}, kind: ${c.kind}, url: ${c.url}, branch: ${c.branch}, path: ${c.path}, repo: ${c.repo}, base_image: ${c.base_image}, force: ${c.force} }'
}

View File

@ -16,13 +16,13 @@ pub mut:
// str returns a string representation.
pub fn (bl &BuildLog) str() string {
mut parts := [
'id: $bl.id',
'target id: $bl.target_id',
'start time: $bl.start_time.local()',
'end time: $bl.end_time.local()',
'id: ${bl.id}',
'target id: ${bl.target_id}',
'start time: ${bl.start_time.local()}',
'end time: ${bl.end_time.local()}',
'duration: ${bl.end_time - bl.start_time}',
'arch: $bl.arch',
'exit code: $bl.exit_code',
'arch: ${bl.arch}',
'exit code: ${bl.exit_code}',
]
str := parts.join('\n')

View File

@ -4,17 +4,17 @@ import time
// from_params<T> creates a new instance of T from the given map by parsing all
// of its fields from the map.
pub fn from_params<T>(params map[string]string) ?T {
pub fn from_params[T](params map[string]string) ?T {
mut o := T{}
patch_from_params<T>(mut o, params)?
patch_from_params[T](mut o, params)?
return o
}
// patch_from_params<T> updates the given T object with the params defined in
// the map.
pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
pub fn patch_from_params[T](mut o T, params map[string]string) ? {
$for field in T.fields {
if field.name in params && params[field.name] != '' {
$if field.typ is string {
@ -37,7 +37,7 @@ pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
}
// params_from<T> converts a given T struct into a map of strings.
pub fn params_from<T>(o &T) map[string]string {
pub fn params_from[T](o &T) map[string]string {
mut out := map[string]string{}
$for field in T.fields {

View File

@ -38,13 +38,13 @@ pub mut:
// str returns a string representation.
pub fn (t &Target) str() string {
mut parts := [
'id: $t.id',
'kind: $t.kind',
'url: $t.url',
'branch: $t.branch',
'path: $t.path',
'repo: $t.repo',
'schedule: $t.schedule',
'id: ${t.id}',
'kind: ${t.kind}',
'url: ${t.url}',
'branch: ${t.branch}',
'path: ${t.path}',
'repo: ${t.repo}',
'schedule: ${t.schedule}',
'arch: ${t.arch.map(it.value).join(', ')}',
]
str := parts.join('\n')

View File

@ -3,14 +3,14 @@ module package
// format_entry returns a string properly formatted to be added to a desc file.
[inline]
fn format_entry(key string, value string) string {
return '\n%$key%\n$value\n'
return '\n%${key}%\n${value}\n'
}
// full_name returns the properly formatted name for the package, including
// version & architecture
pub fn (pkg &Pkg) full_name() string {
p := pkg.info
return '$p.name-$p.version-$p.arch'
return '${p.name}-${p.version}-${p.arch}'
}
// filename returns the correct filename of the package file
@ -20,10 +20,10 @@ pub fn (pkg &Pkg) filename() string {
1 { '.tar.gz' }
6 { '.tar.xz' }
14 { '.tar.zst' }
else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") }
else { panic("Another compression code shouldn't be possible. Faulty code: ${pkg.compression}") }
}
return '${pkg.full_name()}.pkg$ext'
return '${pkg.full_name()}.pkg${ext}'
}
// to_desc returns a desc file valid string representation
@ -31,7 +31,7 @@ pub fn (pkg &Pkg) to_desc() !string {
p := pkg.info
// filename
mut desc := '%FILENAME%\n$pkg.filename()\n'
mut desc := '%FILENAME%\n${pkg.filename()}\n'
desc += format_entry('NAME', p.name)
desc += format_entry('BASE', p.base)
@ -94,10 +94,10 @@ pub fn (pkg &Pkg) to_desc() !string {
desc += format_entry('CHECKDEPENDS', p.checkdepends.join_lines())
}
return '$desc\n'
return '${desc}\n'
}
// to_files returns a files file valid string representation
pub fn (pkg &Pkg) to_files() string {
return '%FILES%\n$pkg.files.join_lines()\n'
return '%FILES%\n${pkg.files.join_lines()}\n'
}

View File

@ -103,7 +103,7 @@ fn parse_pkg_info_string(pkg_info_str &string) !PkgInfo {
// NOTE: this command only supports zstd-, xz- & gzip-compressed tarballs.
pub fn read_pkg_archive(pkg_path string) !Pkg {
if !os.is_file(pkg_path) {
return error("'$pkg_path' doesn't exist or isn't a file.")
return error("'${pkg_path}' doesn't exist or isn't a file.")
}
a := C.archive_read_new()

View File

@ -31,11 +31,15 @@ pub:
// new creates a new RepoGroupManager & creates the directories as needed
pub fn new(repos_dir string, pkg_dir string, default_arch string) !RepoGroupManager {
if !os.is_dir(repos_dir) {
os.mkdir_all(repos_dir) or { return error('Failed to create repos directory: $err.msg()') }
os.mkdir_all(repos_dir) or {
return error('Failed to create repos directory: ${err.msg()}')
}
}
if !os.is_dir(pkg_dir) {
os.mkdir_all(pkg_dir) or { return error('Failed to create package directory: $err.msg()') }
os.mkdir_all(pkg_dir) or {
return error('Failed to create package directory: ${err.msg()}')
}
}
return RepoGroupManager{
@ -51,7 +55,7 @@ pub fn new(repos_dir string, pkg_dir string, default_arch string) !RepoGroupMana
// the right subdirectories in r.pkg_dir if it was successfully added.
pub fn (r &RepoGroupManager) add_pkg_from_path(repo string, pkg_path string) !RepoAddResult {
pkg := package.read_pkg_archive(pkg_path) or {
return error('Failed to read package file: $err.msg()')
return error('Failed to read package file: ${err.msg()}')
}
archs := r.add_pkg_in_repo(repo, pkg)!
@ -129,7 +133,7 @@ fn (r &RepoGroupManager) add_pkg_in_repo(repo string, pkg &package.Pkg) ![]strin
// files, and afterwards updates the db & files archives to reflect these
// changes.
fn (r &RepoGroupManager) add_pkg_in_arch_repo(repo string, arch string, pkg &package.Pkg) ! {
pkg_dir := os.join_path(r.repos_dir, repo, arch, '$pkg.info.name-$pkg.info.version')
pkg_dir := os.join_path(r.repos_dir, repo, arch, '${pkg.info.name}-${pkg.info.version}')
// Remove the previous version of the package, if present
r.remove_pkg_from_arch_repo(repo, arch, pkg.info.name, false)!

View File

@ -13,7 +13,7 @@ import models { BuildLog, BuildLogFilter }
// optionally be added to limit the list of build logs to that repository.
['/api/v1/logs'; auth; get; markused]
fn (mut app App) v1_get_logs() web.Result {
filter := models.from_params<BuildLogFilter>(app.query) or {
filter := models.from_params[BuildLogFilter](app.query) or {
return app.json(.bad_request, new_response('Invalid query parameters.'))
}
logs := app.db.get_build_logs(filter)
@ -101,7 +101,7 @@ fn (mut app App) v1_post_log() web.Result {
// Create the logs directory of it doesn't exist
if !os.exists(os.dir(log_file_path)) {
os.mkdir_all(os.dir(log_file_path)) or {
app.lerror('Error while creating log file: $err.msg()')
app.lerror('Error while creating log file: ${err.msg()}')
return app.status(.internal_server_error)
}
@ -109,7 +109,7 @@ fn (mut app App) v1_post_log() web.Result {
if length := app.req.header.get(.content_length) {
util.reader_to_file(mut app.reader, length.int(), log_file_path) or {
app.lerror('An error occured while receiving logs: $err.msg()')
app.lerror('An error occured while receiving logs: ${err.msg()}')
return app.status(.internal_server_error)
}
@ -127,7 +127,7 @@ fn (mut app App) v1_delete_log(id int) web.Result {
full_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
os.rm(full_path) or {
app.lerror('Failed to remove log file $full_path: $err.msg()')
app.lerror('Failed to remove log file ${full_path}: ${err.msg()}')
return app.status(.internal_server_error)
}

View File

@ -8,7 +8,7 @@ import models { Target, TargetArch, TargetFilter }
// v1_get_targets returns the current list of targets.
['/api/v1/targets'; auth; get; markused]
fn (mut app App) v1_get_targets() web.Result {
filter := models.from_params<TargetFilter>(app.query) or {
filter := models.from_params[TargetFilter](app.query) or {
return app.json(.bad_request, new_response('Invalid query parameters.'))
}
mut iter := app.db.targets(filter)
@ -35,7 +35,7 @@ fn (mut app App) v1_post_target() web.Result {
params['arch'] = app.conf.default_arch
}
mut new_target := models.from_params<Target>(params) or {
mut new_target := models.from_params[Target](params) or {
return app.json(.bad_request, new_response(err.msg()))
}

View File

@ -25,7 +25,7 @@ pub fn cmd() cli.Command {
description: 'Start the Vieter server.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
server(conf)!
}

View File

@ -12,7 +12,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
for {
mut too_old_timestamp := time.now().add_days(-app.conf.max_log_age)
app.linfo('Cleaning logs before $too_old_timestamp')
app.linfo('Cleaning logs before ${too_old_timestamp}')
mut logs := []BuildLog{}
mut counter := 0
@ -29,7 +29,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
log_file_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
os.rm(log_file_path) or {
app.lerror('Failed to remove log file $log_file_path: $err.msg()')
app.lerror('Failed to remove log file ${log_file_path}: ${err.msg()}')
failed += 1
continue
@ -44,7 +44,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
}
}
app.linfo('Cleaned $counter logs ($failed failed)')
app.linfo('Cleaned ${counter} logs (${failed} failed)')
// Sleep until the next cycle
next_time := schedule.next_from_now()

View File

@ -26,7 +26,7 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
// There's no point in having the ability to serve db archives with wrong
// filenames
if db_exts.any(filename == '$repo$it') {
if db_exts.any(filename == '${repo}${it}') {
full_path = os.join_path(app.repo.repos_dir, repo, arch, filename)
// repo-add does this using symlinks, but we just change the requested
@ -62,19 +62,19 @@ fn (mut app App) put_package(repo string) web.Result {
// Generate a random filename for the temp file
pkg_path = os.join_path_single(app.repo.pkg_dir, rand.uuid_v4())
app.ldebug("Uploading $length bytes (${util.pretty_bytes(length.int())}) to '$pkg_path'.")
app.ldebug("Uploading ${length} bytes (${util.pretty_bytes(length.int())}) to '${pkg_path}'.")
// This is used to time how long it takes to upload a file
mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true })
util.reader_to_file(mut app.reader, length.int(), pkg_path) or {
app.lwarn("Failed to upload '$pkg_path'")
app.lwarn("Failed to upload '${pkg_path}'")
return app.status(.internal_server_error)
}
sw.stop()
app.ldebug("Upload of '$pkg_path' completed in ${sw.elapsed().seconds():.3}s.")
app.ldebug("Upload of '${pkg_path}' completed in ${sw.elapsed().seconds():.3}s.")
} else {
app.lwarn('Tried to upload package without specifying a Content-Length.')
@ -83,14 +83,14 @@ fn (mut app App) put_package(repo string) web.Result {
}
res := app.repo.add_pkg_from_path(repo, pkg_path) or {
app.lerror('Error while adding package: $err.msg()')
app.lerror('Error while adding package: ${err.msg()}')
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg()") }
os.rm(pkg_path) or { app.lerror("Failed to remove download '${pkg_path}': ${err.msg()}") }
return app.status(.internal_server_error)
}
app.linfo("Added '$res.name-$res.version' to '$repo (${res.archs.join(',')})'.")
app.linfo("Added '${res.name}-${res.version}' to '${repo} (${res.archs.join(',')})'.")
return app.json(.ok, new_data_response(res))
}

View File

@ -6,17 +6,17 @@ import web
['/:repo/:arch/:pkg'; auth; delete; markused]
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
app.lerror('Error while deleting package: $err.msg()')
app.lerror('Error while deleting package: ${err.msg()}')
return app.status(.internal_server_error)
}
if res {
app.linfo("Removed package '$pkg' from '$repo/$arch'")
app.linfo("Removed package '${pkg}' from '${repo}/${arch}'")
return app.status(.ok)
} else {
app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.")
app.linfo("Tried removing package '${pkg}' from '${repo}/${arch}', but it doesn't exist.")
return app.status(.not_found)
}
@ -26,17 +26,17 @@ fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result
['/:repo/:arch'; auth; delete; markused]
fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
res := app.repo.remove_arch_repo(repo, arch) or {
app.lerror('Error while deleting arch-repo: $err.msg()')
app.lerror('Error while deleting arch-repo: ${err.msg()}')
return app.status(.internal_server_error)
}
if res {
app.linfo("Removed arch-repo '$repo/$arch'")
app.linfo("Removed arch-repo '${repo}/${arch}'")
return app.status(.ok)
} else {
app.linfo("Tried removing '$repo/$arch', but it doesn't exist.")
app.linfo("Tried removing '${repo}/${arch}', but it doesn't exist.")
return app.status(.not_found)
}
@ -46,17 +46,17 @@ fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
['/:repo'; auth; delete; markused]
fn (mut app App) delete_repo(repo string) web.Result {
res := app.repo.remove_repo(repo) or {
app.lerror('Error while deleting repo: $err.msg()')
app.lerror('Error while deleting repo: ${err.msg()}')
return app.status(.internal_server_error)
}
if res {
app.linfo("Removed repo '$repo'")
app.linfo("Removed repo '${repo}'")
return app.status(.ok)
} else {
app.linfo("Tried removing '$repo', but it doesn't exist.")
app.linfo("Tried removing '${repo}', but it doesn't exist.")
return app.status(.not_found)
}

View File

@ -44,11 +44,11 @@ pub fn server(conf Config) ! {
}
global_ce := cron.parse_expression(conf.global_schedule) or {
util.exit_with_message(1, 'Invalid global cron expression: $err.msg()')
util.exit_with_message(1, 'Invalid global cron expression: ${err.msg()}')
}
log_removal_ce := cron.parse_expression(conf.log_removal_schedule) or {
util.exit_with_message(1, 'Invalid log removal cron expression: $err.msg()')
util.exit_with_message(1, 'Invalid log removal cron expression: ${err.msg()}')
}
// Configure logger
@ -89,7 +89,7 @@ pub fn server(conf Config) ! {
db_file := os.join_path_single(conf.data_dir, server.db_file_name)
db := db.init(db_file) or {
util.exit_with_message(1, 'Failed to initialize database: $err.msg()')
util.exit_with_message(1, 'Failed to initialize database: ${err.msg()}')
}
mut collector := if conf.collect_metrics {
@ -98,8 +98,8 @@ pub fn server(conf Config) ! {
&metrics.MetricsCollector(metrics.new_null_collector())
}
collector.histogram_buckets_set('http_requests_duration_seconds', [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5,
10] )
collector.histogram_buckets_set('http_requests_duration_seconds', [0.001, 0.005, 0.01, 0.05,
0.1, 0.5, 1, 5, 10])
mut app := &App{
logger: logger
@ -111,11 +111,11 @@ pub fn server(conf Config) ! {
job_queue: build.new_job_queue(global_ce, conf.base_image)
}
app.init_job_queue() or {
util.exit_with_message(1, 'Failed to inialize job queue: $err.msg()')
util.exit_with_message(1, 'Failed to inialize job queue: ${err.msg()}')
}
if conf.max_log_age > 0 {
go app.log_removal_daemon(log_removal_ce)
spawn app.log_removal_daemon(log_removal_ce)
}
web.run(app, conf.port)

View File

@ -51,7 +51,7 @@ pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) ! {
// match_array_in_array<T> returns how many elements of a2 overlap with a1. For
// example, if a1 = "abcd" & a2 = "cd", the result will be 2. If the match is
// not at the end of a1, the result is 0.
pub fn match_array_in_array<T>(a1 []T, a2 []T) int {
pub fn match_array_in_array[T](a1 []T, a2 []T) int {
mut i := 0
mut match_len := 0

View File

@ -10,7 +10,7 @@ const attrs_to_ignore = ['auth', 'markused']
// Parsing function attributes for methods and path.
fn parse_attrs(name string, attrs []string) !([]http.Method, string) {
if attrs.len == 0 {
return [http.Method.get], '/$name'
return [http.Method.get], '/${name}'
}
mut x := attrs.clone()
@ -45,7 +45,7 @@ fn parse_attrs(name string, attrs []string) !([]http.Method, string) {
methods = [http.Method.get]
}
if path == '' {
path = '/$name'
path = '/${name}'
}
// Make path lowercase for case-insensitive comparisons
return methods, path.to_lower()

View File

@ -1,6 +1,6 @@
module response
pub struct Response<T> {
pub struct Response[T] {
pub:
message string
data T
@ -8,8 +8,8 @@ pub:
// 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>{
pub fn new_response(message string) Response[string] {
return Response[string]{
message: message
data: ''
}
@ -17,8 +17,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>{
pub fn new_data_response[T](data T) Response[T] {
return Response[T]{
message: ''
data: data
}
@ -26,8 +26,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>{
pub fn new_full_response[T](message string, data T) Response[T] {
return Response[T]{
message: message
data: data
}

View File

@ -158,7 +158,7 @@ pub fn (mut ctx Context) body(status http.Status, content_type string, body stri
}
// json<T> HTTP_OK with json_s as payload with content-type `application/json`
pub fn (mut ctx Context) json<T>(status http.Status, j T) Result {
pub fn (mut ctx Context) json[T](status http.Status, j T) Result {
ctx.status = status
ctx.content_type = 'application/json'
@ -278,14 +278,14 @@ interface DbInterface {
// run runs the app
[manualfree]
pub fn run<T>(global_app &T, port int) {
mut l := net.listen_tcp(.ip6, ':$port') or { panic('failed to listen $err.code() $err') }
pub fn run[T](global_app &T, port int) {
mut l := net.listen_tcp(.ip6, ':${port}') or { panic('failed to listen ${err.code()} ${err}') }
// Parsing methods attributes
mut routes := map[string]Route{}
$for method in T.methods {
http_methods, route_path := parse_attrs(method.name, method.attrs) or {
eprintln('error parsing method attributes: $err')
eprintln('error parsing method attributes: ${err}')
return
}
@ -294,7 +294,7 @@ pub fn run<T>(global_app &T, port int) {
path: route_path
}
}
println('[Vweb] Running app on http://localhost:$port')
println('[Vweb] Running app on http://localhost:${port}')
for {
// Create a new app object for each connection, copy global data like db connections
mut request_app := &T{}
@ -311,16 +311,16 @@ pub fn run<T>(global_app &T, port int) {
request_app.Context = global_app.Context // copy the context ref that contains static files map etc
mut conn := l.accept() or {
// failures should not panic
eprintln('accept() failed with error: $err.msg()')
eprintln('accept() failed with error: ${err.msg()}')
continue
}
go handle_conn<T>(mut conn, mut request_app, routes)
spawn handle_conn[T](mut conn, mut request_app, routes)
}
}
// handle_conn handles a connection
[manualfree]
fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
fn handle_conn[T](mut conn net.TcpConn, mut app T, routes map[string]Route) {
conn.set_read_timeout(30 * time.second)
conn.set_write_timeout(30 * time.second)
@ -362,8 +362,8 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// Request parse
head := http.parse_request_head(mut reader) or {
// Prevents errors from being thrown when BufferedReader is empty
if '$err' != 'none' {
eprintln('error parsing request head: $err')
if '${err}' != 'none' {
eprintln('error parsing request head: ${err}')
}
return
}
@ -371,7 +371,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// The healthcheck spams the logs, which isn't very useful
if head.url != '/health' {
lock app.logger {
app.logger.debug('$head.method $head.url $head.version')
app.logger.debug('${head.method} ${head.url} ${head.version}')
}
}
@ -385,7 +385,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// URL Parse
url := urllib.parse(head.url) or {
eprintln('error parsing path: $err')
eprintln('error parsing path: ${err}')
return
}
@ -423,7 +423,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
$for method in T.methods {
$if method.return_type is Result {
route := routes[method.name] or {
eprintln('parsed attributes for the `$method.name` are not found, skipping...')
eprintln('parsed attributes for the `${method.name}` are not found, skipping...')
Route{}
}
@ -455,7 +455,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
method_args := params.clone()
if method_args.len != method.args.len {
eprintln('warning: uneven parameters count ($method.args.len) in `$method.name`, compared to the web route `$method.attrs` ($method_args.len)')
eprintln('warning: uneven parameters count (${method.args.len}) in `${method.name}`, compared to the web route `${method.attrs}` (${method_args.len})')
}
app.$method(method_args)
return