simplified server config

Jef Roosens 2022-05-03 16:54:12 +02:00
parent ac91cfebb2
commit 88b32f376f
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 17 additions and 16 deletions

View File

@ -6,12 +6,9 @@ import env
struct Config { struct Config {
pub: pub:
log_level string = 'WARN' log_level string = 'WARN'
log_file string = 'vieter.log'
pkg_dir string pkg_dir string
download_dir string data_dir string
api_key string api_key string
repos_dir string
repos_file string
default_arch string default_arch string
} }

View File

@ -68,7 +68,7 @@ fn (mut app App) put_package(repo string) web.Result {
if length := app.req.header.get(.content_length) { if length := app.req.header.get(.content_length) {
// Generate a random filename for the temp file // Generate a random filename for the temp file
pkg_path = os.join_path_single(app.conf.download_dir, rand.uuid_v4()) 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'.")

View File

@ -7,7 +7,12 @@ import repo
import util import util
import db import db
const port = 8000 const (
port = 8000
log_file_name = 'vieter.log'
repo_dir_name = 'repos'
db_file_name = 'vieter.sqlite'
)
struct App { struct App {
web.Context web.Context
@ -32,11 +37,14 @@ pub fn server(conf Config) ? {
util.exit_with_message(1, 'Invalid log level. The allowed values are FATAL, ERROR, WARN, INFO & DEBUG.') util.exit_with_message(1, 'Invalid log level. The allowed values are FATAL, ERROR, WARN, INFO & DEBUG.')
} }
os.mkdir_all(conf.data_dir) or { util.exit_with_message(1, 'Failed to create data directory.') }
mut logger := log.Log{ mut logger := log.Log{
level: log_level level: log_level
} }
logger.set_full_logpath(conf.log_file) log_file := os.join_path_single(conf.data_dir, server.log_file_name)
logger.set_full_logpath(log_file)
logger.log_to_console_too() logger.log_to_console_too()
defer { defer {
@ -45,17 +53,15 @@ pub fn server(conf Config) ? {
logger.close() logger.close()
} }
repo_dir := os.join_path_single(conf.data_dir, server.repo_dir_name)
// This also creates the directories if needed // This also creates the directories if needed
repo := repo.new(conf.repos_dir, conf.pkg_dir, conf.default_arch) or { repo := repo.new(repo_dir, conf.pkg_dir, conf.default_arch) or {
logger.error(err.msg()) logger.error(err.msg())
exit(1) exit(1)
} }
os.mkdir_all(conf.download_dir) or { db_file := os.join_path_single(conf.data_dir, server.db_file_name)
util.exit_with_message(1, 'Failed to create download directory.') db := db.init(db_file) or { util.exit_with_message(1, 'Failed to initialize database.') }
}
db := db.init('test.db') or { util.exit_with_message(1, 'Failed to initialize database.') }
web.run(&App{ web.run(&App{
logger: logger logger: logger

View File

@ -1,10 +1,8 @@
# This file contains settings used during development # This file contains settings used during development
api_key = "test" api_key = "test"
download_dir = "data/downloads" data_dir = "data"
repos_dir = "data/repos"
pkg_dir = "data/pkgs" pkg_dir = "data/pkgs"
log_level = "DEBUG" log_level = "DEBUG"
repos_file = "data/repos.json"
default_arch = "x86_64" default_arch = "x86_64"
address = "http://localhost:8000" address = "http://localhost:8000"