Skip to content

Commit ea84f10

Browse files
authored
fix compilation with latest V, add a CI (#30)
1 parent 6126632 commit ea84f10

File tree

5 files changed

+60
-26
lines changed

5 files changed

+60
-26
lines changed

.github/workflows/ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
pull_request:
7+
8+
jobs:
9+
basic-checks:
10+
runs-on: ubuntu-20.04
11+
steps:
12+
13+
- name: Checkout V
14+
uses: actions/checkout@v2
15+
with:
16+
repository: vlang/v
17+
18+
- name: Checkout vorum
19+
uses: actions/checkout@v2
20+
with:
21+
path: vorum
22+
23+
- name: Build V
24+
run: |
25+
make
26+
./v symlink -githubci
27+
28+
- name: Build Vorum
29+
run: v vorum
30+
31+
- name: Check Vorum code is VFMTed
32+
run: v fmt -verify vorum/
33+
34+
- name: Vet Vorum
35+
run: v vet vorum

main.v

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ import net.http
66
import time
77
import log
88

9-
const (
10-
port = 8092
11-
db_name = 'vorum'
12-
db_user = 'vorum'
13-
)
9+
const port = 8092
10+
const db_name = 'vorum'
11+
const db_user = 'vorum'
1412

1513
pub struct App {
1614
vweb.Context
1715
pub mut:
1816
db pg.DB
1917
user User
2018
logged_in bool
21-
logger log.Log [vweb_global]
19+
logger log.Log @[vweb_global]
2220
}
2321

2422
fn main() {
@@ -49,7 +47,7 @@ pub fn (mut app App) index() vweb.Result {
4947
return $vweb.html()
5048
}
5149

52-
['/post/:id']
50+
@['/post/:id']
5351
pub fn (mut app App) post(id int) vweb.Result {
5452
post := app.get_post(id) or { return app.text('Discussion not found.') }
5553
app.inc_post_views(id) or { app.warn(err.str()) }
@@ -69,7 +67,7 @@ pub fn (mut app App) new() vweb.Result {
6967
return $vweb.html()
7068
}
7169

72-
[post]
70+
@[post]
7371
pub fn (mut app App) new_post() vweb.Result {
7472
app.auth()
7573

@@ -89,7 +87,7 @@ pub fn (mut app App) new_post() vweb.Result {
8987
return app.redirect('/')
9088
}
9189

92-
['/comment/:post_id'; post]
90+
@['/comment/:post_id'; post]
9391
fn (mut app App) comment(post_id int) vweb.Result {
9492
app.auth()
9593

@@ -110,7 +108,7 @@ fn (mut app App) comment(post_id int) vweb.Result {
110108
return app.redirect('/post/${post_id}') // so that refreshing a page won't do a post again
111109
}
112110

113-
['/posts/:id'; delete]
111+
@['/posts/:id'; delete]
114112
pub fn (mut app App) deletepost(post_id int) vweb.Result {
115113
app.auth()
116114

oauth.v

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import json
55
import os
66
import vweb
77

8-
const (
9-
// oauth_client_id = os.getenv('VORUM_OAUTH_CLIENT_ID')
10-
// oauth_client_secret = os.getenv('VORUM_OAUTH_SECRET')
11-
client_id = os.getenv('VORUM_OAUTH_CLIENT_ID')
12-
client_secret = os.getenv('VORUM_OAUTH_SECRET')
13-
)
8+
// oauth_client_id = os.getenv('VORUM_OAUTH_CLIENT_ID')
9+
// oauth_client_secret = os.getenv('VORUM_OAUTH_SECRET')
10+
const client_id = os.getenv('VORUM_OAUTH_CLIENT_ID')
11+
const client_secret = os.getenv('VORUM_OAUTH_SECRET')
1412

1513
struct GitHubUser {
1614
login string

post.v

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ module main
22

33
import time
44

5-
[table: 'posts']
5+
@[table: 'posts']
66
struct Post {
77
id int
88
title string
99
text string
10-
url string [skip]
10+
url string @[skip]
1111
nr_comments int
12-
time time.Time [orm: skip]
12+
time time.Time @[orm: skip]
1313
last_reply time.Time
1414
nr_views int
1515
is_locked bool
1616
is_blog bool
1717
is_deleted bool
1818
}
1919

20-
[table: 'comments']
20+
@[table: 'comments']
2121
struct Comment {
2222
id int
2323
post_id int
@@ -48,13 +48,16 @@ order by last_reply desc')!
4848
for row in rows {
4949
id := row.vals[0]
5050
title := row.vals[1]
51+
nr_comments := row.vals[4]
52+
ts := row.vals[3]
53+
is_locked := row.vals[5]
5154
posts << Post{
52-
id: id.int()
55+
id: id or { '' }.int()
5356
url: '/post/${id}'
54-
title: title
55-
nr_comments: row.vals[4].int()
56-
time: time.unix(row.vals[3].int())
57-
is_locked: row.vals[5] == 't'
57+
title: title or { '' }
58+
nr_comments: nr_comments or { '' }.int()
59+
time: time.unix(ts or { '' }.int())
60+
is_locked: is_locked or { '' } == 't'
5861
}
5962
}
6063
return posts

user.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module main
22

3-
[table: 'users']
3+
@[table: 'users']
44
struct User {
55
mut:
66
id int

0 commit comments

Comments
 (0)