Skip to content

Commit

Permalink
veb: deprecate vweb (part 1); update the blog tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Mar 1, 2025
1 parent 8dbde18 commit f83af8a
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 114 deletions.
17 changes: 10 additions & 7 deletions cmd/tools/gen_vc.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os
import log
import flag
import time
import vweb
import veb
import net.urllib

// This tool regenerates V's bootstrap .c files
Expand Down Expand Up @@ -79,11 +79,14 @@ mut:

// webhook server
struct WebhookServer {
vweb.Context
mut:
gen_vc &GenVC = unsafe { nil } // initialized in init_server
}

struct Context {
veb.Context
}

// storage for flag options
struct FlagOptions {
work_dir string
Expand Down Expand Up @@ -116,7 +119,8 @@ fn main() {
}
// webhook server mode
if flag_options.serve {
vweb.run[WebhookServer](&WebhookServer{}, flag_options.port)
mut server := &WebhookServer{}
veb.run_at[WebhookServer, Context](mut server, port: flag_options.port)!
} else {
// cmd mode
mut gen_vc := new_gen_vc(flag_options)
Expand Down Expand Up @@ -152,18 +156,17 @@ pub fn (mut ws WebhookServer) index() {
}

// gen webhook
pub fn (mut ws WebhookServer) genhook() {
pub fn (mut ws WebhookServer) genhook() veb.Result {
// request data
// println(ws.vweb.req.data)
// TODO: parse request. json or urlencoded
// json.decode or net.urllib.parse
ws.gen_vc.generate()
// error in generate
if ws.gen_vc.gen_error {
ws.json('{status: "failed"}')
return
return ctx.json('{status: "failed"}')
}
ws.json('{status: "ok"}')
return ctx.json('{status: "ok"}')
}

pub fn (ws &WebhookServer) reset() {
Expand Down
Loading

0 comments on commit f83af8a

Please sign in to comment.