a mini social media app for small communities
1module main 2 3import db.pg 4import veb 5import auth 6import entity 7import os 8 9fn init_db(db pg.DB) ! { 10 sql db { 11 create table entity.Site 12 create table entity.User 13 create table entity.Post 14 create table entity.Like 15 create table entity.LikeCache 16 }! 17} 18 19fn main() { 20 config := load_config_from(os.args[1]) 21 22 mut db := pg.connect(pg.Config{ 23 host: config.postgres.host 24 dbname: config.postgres.db 25 user: config.postgres.user 26 password: config.postgres.password 27 port: config.postgres.port 28 })! 29 30 defer { 31 db.close() 32 } 33 34 mut app := &App{ 35 config: config 36 db: db 37 auth: auth.new(db) 38 } 39 40 // vfmt off 41 app.validators.username = StringValidator.new(config.user.username_min_len, config.user.username_max_len, config.user.username_pattern) 42 app.validators.password = StringValidator.new(config.user.username_min_len, config.user.username_max_len, config.user.username_pattern) 43 app.validators.nickname = StringValidator.new(config.user.nickname_min_len, config.user.nickname_max_len, config.user.nickname_pattern) 44 app.validators.user_bio = StringValidator.new(config.user.bio_min_len, config.user.bio_max_len, config.user.bio_pattern) 45 app.validators.pronouns = StringValidator.new(config.user.pronouns_min_len, config.user.pronouns_max_len, config.user.pronouns_pattern) 46 app.validators.post_title = StringValidator.new(config.post.title_min_len, config.post.title_max_len, config.post.title_pattern) 47 app.validators.post_body = StringValidator.new(config.post.body_min_len, config.post.body_max_len, config.post.body_pattern) 48 // vfmt on 49 50 app.mount_static_folder_at(app.config.static_path, '/static')! 51 init_db(db)! 52 53 // make the website config, if it does not exist 54 app.get_or_create_site_config() 55 56 if config.dev_mode { 57 println('\033[1;31mNOTE: YOU ARE IN DEV MODE\033[0m') 58 } 59 60 veb.run[App, Context](mut app, app.config.http.port) 61}