mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: check (mut f Foo)
syntax
This commit is contained in:
@ -33,12 +33,12 @@ pub fn new_manager() &AssetManager {
|
||||
}
|
||||
|
||||
// add_css adds a css asset
|
||||
pub fn (am mut AssetManager) add_css(file string) bool {
|
||||
pub fn (mut am AssetManager) add_css(file string) bool {
|
||||
return am.add('css', file)
|
||||
}
|
||||
|
||||
// add_js adds a js asset
|
||||
pub fn (am mut AssetManager) add_js(file string) bool {
|
||||
pub fn (mut am AssetManager) add_js(file string) bool {
|
||||
return am.add('js', file)
|
||||
}
|
||||
|
||||
@ -149,8 +149,8 @@ fn (am AssetManager) include(asset_type string, combine bool) string {
|
||||
}
|
||||
|
||||
// dont return option until size limit is removed
|
||||
// fn (am mut AssetManager) add(asset_type, file string) ?bool {
|
||||
fn (am mut AssetManager) add(asset_type, file string) bool {
|
||||
// fn (mut am AssetManager) add(asset_type, file string) ?bool {
|
||||
fn (mut am AssetManager) add(asset_type, file string) bool {
|
||||
if !os.exists(file) {
|
||||
// return error('vweb.assets: cannot add asset $file, it does not exist')
|
||||
return false
|
||||
|
@ -48,7 +48,7 @@ mut:
|
||||
done bool
|
||||
}
|
||||
|
||||
fn (ctx mut Context) send_response_to_client(mimetype string, res string) bool {
|
||||
fn (mut ctx Context) send_response_to_client(mimetype string, res string) bool {
|
||||
if ctx.done { return false }
|
||||
ctx.done = true
|
||||
mut sb := strings.new_builder(1024)
|
||||
@ -63,31 +63,31 @@ fn (ctx mut Context) send_response_to_client(mimetype string, res string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) html(s string) {
|
||||
pub fn (mut ctx Context) html(s string) {
|
||||
ctx.send_response_to_client('text/html', s)
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) text(s string) {
|
||||
pub fn (mut ctx Context) text(s string) {
|
||||
ctx.send_response_to_client('text/plain', s)
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) json(s string) {
|
||||
pub fn (mut ctx Context) json(s string) {
|
||||
ctx.send_response_to_client('application/json', s)
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) redirect(url string) {
|
||||
pub fn (mut ctx Context) redirect(url string) {
|
||||
if ctx.done { return }
|
||||
ctx.done = true
|
||||
ctx.conn.send_string('HTTP/1.1 302 Found\r\nLocation: ${url}${ctx.headers}\r\n${HEADERS_CLOSE}') or { return }
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) not_found(s string) {
|
||||
pub fn (mut ctx Context) not_found(s string) {
|
||||
if ctx.done { return }
|
||||
ctx.done = true
|
||||
ctx.conn.send_string(HTTP_404) or { return }
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) set_cookie(key, val string) {
|
||||
pub fn (mut ctx Context) set_cookie(key, val string) {
|
||||
// TODO support directives, escape cookie value (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
|
||||
//println('Set-Cookie $key=$val')
|
||||
ctx.add_header('Set-Cookie', '${key}=${val}; Secure; HttpOnly')
|
||||
@ -112,7 +112,7 @@ pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
|
||||
return error('Cookie not found')
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) add_header(key, val string) {
|
||||
pub fn (mut ctx Context) add_header(key, val string) {
|
||||
//println('add_header($key, $val)')
|
||||
ctx.headers = ctx.headers + '\r\n$key: $val'
|
||||
//println(ctx.headers)
|
||||
@ -290,7 +290,7 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
|
||||
app.reset()
|
||||
}
|
||||
|
||||
fn (ctx mut Context) parse_form(s string) {
|
||||
fn (mut ctx Context) parse_form(s string) {
|
||||
if ctx.req.method !in methods_with_form {
|
||||
return
|
||||
}
|
||||
@ -319,7 +319,7 @@ fn (ctx mut Context) parse_form(s string) {
|
||||
// ...
|
||||
}
|
||||
|
||||
fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
|
||||
fn (mut ctx Context) scan_static_directory(directory_path, mount_path string) {
|
||||
files := os.ls(directory_path) or { panic(err) }
|
||||
|
||||
if files.len > 0 {
|
||||
@ -340,7 +340,7 @@ fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) handle_static(directory_path string) bool {
|
||||
pub fn (mut ctx Context) handle_static(directory_path string) bool {
|
||||
if ctx.done || ! os.exists(directory_path) {
|
||||
return false
|
||||
}
|
||||
@ -358,7 +358,7 @@ pub fn (ctx mut Context) handle_static(directory_path string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn (ctx mut Context) serve_static(url, file_path, mime_type string) {
|
||||
pub fn (mut ctx Context) serve_static(url, file_path, mime_type string) {
|
||||
ctx.static_files[url] = file_path
|
||||
ctx.static_mime_types[url] = mime_type
|
||||
}
|
||||
|
Reference in New Issue
Block a user