forked from vieter-v/vieter
Added Dockerfile & beginning of vweb server
This commit is contained in:
parent
9a09db0485
commit
65f113cdee
7 changed files with 65 additions and 11 deletions
9
vieter/fibonacci.v
Normal file
9
vieter/fibonacci.v
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
module fibonacci
|
||||
|
||||
pub fn fib(i int) int {
|
||||
if i <= 1 {
|
||||
return i
|
||||
}
|
||||
|
||||
return fib(i - 1) + fib(i - 2)
|
||||
}
|
||||
37
vieter/main.v
Normal file
37
vieter/main.v
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
module main
|
||||
|
||||
import vweb
|
||||
import os
|
||||
|
||||
const port = 8000
|
||||
|
||||
struct App {
|
||||
vweb.Context
|
||||
api_key string [required]
|
||||
repo_dir string [required]
|
||||
}
|
||||
|
||||
[noreturn]
|
||||
fn exit_with_message(code int, msg string) {
|
||||
eprintln(msg)
|
||||
exit(code)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
key := os.getenv_opt('API_KEY') or { exit_with_message(1, 'No API key was provided.') }
|
||||
repo_dir := os.getenv_opt('REPO_DIR') or {
|
||||
exit_with_message(1, 'No repo directory was configured.')
|
||||
}
|
||||
|
||||
// We create the upload directory during startup
|
||||
if !os.is_dir(repo_dir) {
|
||||
os.mkdir_all(repo_dir) or { exit_with_message(2, 'Failed to create repo directory.') }
|
||||
|
||||
println('Repo directory created.')
|
||||
}
|
||||
|
||||
vweb.run(&App{
|
||||
api_key: key
|
||||
repo_dir: repo_dir
|
||||
}, port)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue