Setting up the vweb web server
We will set up the web server in the main.v
file by performing the following steps:
- To begin, import the
vweb
andsqlite
modules, as shown in the following code:// file: main.v module main import vweb import sqlite
- Next, we will create a struct, named
App
, which appears as follows:// file: main.v struct App { vweb.Context mut: db sqlite.DB }
The preceding code shows the
App
struct, which holdsvweb.Context
along with fields such as theport
field on which our app will be running and a mutabledb
field of thesqlite.DB
type. - Next, we will modify the
main
function, which will appear as follows:// file: main.v fn main() { db := sqlite.connect('notes.db') or { panic(err) } db.exec('drop table if exists Notes') ...