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 validators: struct { 39 username: StringValidator.new(config.user.username_min_len, config.user.username_max_len, config.user.username_pattern) 40 password: StringValidator.new(config.user.username_min_len, config.user.username_max_len, config.user.username_pattern) 41 nickname: StringValidator.new(config.user.nickname_min_len, config.user.nickname_max_len, config.user.nickname_pattern) 42 user_bio: StringValidator.new(config.user.bio_min_len, config.user.bio_max_len, config.user.bio_pattern) 43 pronouns: StringValidator.new(config.user.pronouns_min_len, config.user.pronouns_max_len, config.user.pronouns_pattern) 44 post_title: StringValidator.new(config.post.title_min_len, config.post.title_max_len, config.post.title_pattern) 45 post_body: StringValidator.new(config.post.body_min_len, config.post.body_max_len, config.post.body_pattern) 46 } 47 } 48 49 app.mount_static_folder_at(app.config.static_path, '/static')! 50 init_db(db)! 51 52 // make the website config, if it does not exist 53 app.get_or_create_site_config() 54 55 if config.dev_mode { 56 println('\033[1;31mNOTE: YOU ARE IN DEV MODE\033[0m') 57 } 58 59 veb.run[App, Context](mut app, app.config.http.port) 60}