mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
veb: deprecate vweb (part 1); update the blog tutorial
This commit is contained in:
parent
8dbde185ef
commit
f83af8a1a2
4 changed files with 134 additions and 114 deletions
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -152,7 +156,7 @@ 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
|
||||
|
@ -160,10 +164,9 @@ pub fn (mut ws WebhookServer) genhook() {
|
|||
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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue