1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: unify const names to snake_case

This commit is contained in:
yuyi
2020-05-22 23:36:09 +08:00
committed by GitHub
parent aef751861d
commit dda875a9c8
58 changed files with 543 additions and 540 deletions

View File

@@ -8,7 +8,7 @@ import time
import crypto.md5
const (
UnknownAssetTypeError = 'vweb.assets: unknown asset type'
unknown_asset_type_error = 'vweb.assets: unknown asset type'
)
struct AssetManager {
@@ -164,7 +164,7 @@ fn (mut am AssetManager) add(asset_type, file string) bool {
} else if asset_type == 'js' {
am.js << asset
} else {
panic('$UnknownAssetTypeError ($asset_type).')
panic('$unknown_asset_type_error ($asset_type).')
}
return true
}
@@ -181,7 +181,7 @@ fn (am AssetManager) exists(asset_type, file string) bool {
fn (am AssetManager) get_assets(asset_type string) []Asset {
if asset_type != 'css' && asset_type != 'js' {
panic('$UnknownAssetTypeError ($asset_type).')
panic('$unknown_asset_type_error ($asset_type).')
}
assets := if asset_type == 'css' {
am.css

View File

@@ -7,8 +7,8 @@ import os
import strings
const (
STR_START = "sb.write(\'"
STR_END = "\' ) "
str_start = "sb.write(\'"
str_end = "\' ) "
)
pub fn compile_template(path string) string {
@@ -33,7 +33,7 @@ header := \' \' // TODO remove
_ = header
//footer := \'footer\'
")
s.writeln(STR_START)
s.writeln(str_start)
mut in_css := true // false
for _line in lines {
line := _line.trim_space()
@@ -44,30 +44,30 @@ _ = header
// in_css = false
}
if line.contains('@if ') {
s.writeln(STR_END)
s.writeln(str_end)
pos := line.index('@if') or {
continue
}
s.writeln('if ' + line[pos + 4..] + '{')
s.writeln(STR_START)
s.writeln(str_start)
}
else if line.contains('@end') {
s.writeln(STR_END)
s.writeln(str_end)
s.writeln('}')
s.writeln(STR_START)
s.writeln(str_start)
}
else if line.contains('@else') {
s.writeln(STR_END)
s.writeln(str_end)
s.writeln(' } else { ')
s.writeln(STR_START)
s.writeln(str_start)
}
else if line.contains('@for') {
s.writeln(STR_END)
s.writeln(str_end)
pos := line.index('@for') or {
continue
}
s.writeln('for ' + line[pos + 4..] + '{')
s.writeln(STR_START)
s.writeln(str_start)
}
else if !in_css && line.contains('.') && line.ends_with('{') {
class := line.find_between('.', '{')
@@ -81,8 +81,7 @@ _ = header
s.writeln(line.replace('@', '\x24').replace("'", '"'))
}
}
s.writeln(STR_END)
s.writeln(str_end)
s.writeln('tmpl_res := sb.str() }')
return s.str()
}

View File

@@ -13,11 +13,11 @@ import strings
pub const (
methods_with_form = ['POST', 'PUT', 'PATCH']
method_all = ['GET','POST','PUT','PATCH','DELETE']
HEADER_SERVER = 'Server: VWeb\r\n'
HEADER_CONNECTION_CLOSE = 'Connection: close\r\n'
HEADERS_CLOSE = '${HEADER_SERVER}${HEADER_CONNECTION_CLOSE}\r\n'
HTTP_404 = 'HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\n${HEADERS_CLOSE}404 Not Found'
HTTP_500 = 'HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/plain\r\n${HEADERS_CLOSE}500 Internal Server Error'
header_server = 'Server: VWeb\r\n'
header_connection_close = 'Connection: close\r\n'
headers_close = '${header_server}${header_connection_close}\r\n'
http_404 = 'HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\n${headers_close}404 Not Found'
http_500 = 'HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/plain\r\n${headers_close}500 Internal Server Error'
mime_types = {
'.css': 'text/css; charset=utf-8',
'.gif': 'image/gif',
@@ -31,8 +31,8 @@ pub const (
'.svg': 'image/svg+xml',
'.xml': 'text/xml; charset=utf-8'
}
MAX_HTTP_POST_SIZE = 1024 * 1024
Default_Port = 8080
max_http_post_size = 1024 * 1024
default_port = 8080
)
pub struct Context {
@@ -56,7 +56,7 @@ fn (mut ctx Context) send_response_to_client(mimetype string, res string) bool {
sb.write('\r\nContent-Length: ') sb.write(res.len.str())
sb.write(ctx.headers)
sb.write('\r\n')
sb.write(HEADERS_CLOSE)
sb.write(headers_close)
sb.write(res)
ctx.conn.send_string(sb.str()) or { return false }
sb.free()
@@ -78,13 +78,13 @@ pub fn (mut ctx Context) json(s 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 }
ctx.conn.send_string('HTTP/1.1 302 Found\r\nLocation: ${url}${ctx.headers}\r\n${headers_close}') or { return }
}
pub fn (mut ctx Context) not_found(s string) {
if ctx.done { return }
ctx.done = true
ctx.conn.send_string(HTTP_404) or { return }
ctx.conn.send_string(http_404) or { return }
}
pub fn (mut ctx Context) set_cookie(key, val string) {
@@ -147,9 +147,9 @@ pub fn run<T>(port int) {
//message := readall(conn)
//println(message)
/*
if message.len > MAX_HTTP_POST_SIZE {
println('message.len = $message.len > MAX_HTTP_POST_SIZE')
conn.send_string(HTTP_500) or {}
if message.len > max_http_post_size {
println('message.len = $message.len > max_http_post_size')
conn.send_string(http_500) or {}
conn.close() or {}
continue
}
@@ -160,7 +160,7 @@ pub fn run<T>(port int) {
/*
if lines.len < 2 {
conn.send_string(HTTP_500) or {}
conn.send_string(http_500) or {}
conn.close() or {}
continue
}
@@ -179,7 +179,7 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
vals := first_line.split(' ')
if vals.len < 2 {
println('no vals for http')
conn.send_string(HTTP_500) or {}
conn.send_string(http_500) or {}
conn.close() or {}
return
//continue
@@ -272,7 +272,7 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
if static_file != '' && mime_type != '' {
data := os.read_file(static_file) or {
conn.send_string(HTTP_404) or {}
conn.send_string(http_404) or {}
return
}
app.vweb.send_response_to_client(mime_type, data)
@@ -284,7 +284,7 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
println('action=$action')
}
app.$action() or {
conn.send_string(HTTP_404) or {}
conn.send_string(http_404) or {}
}
conn.close() or {}
app.reset()
@@ -374,7 +374,7 @@ fn readall(conn net.Socket) string {
n := C.recv(conn.sockfd, buf, 1024, 0)
m := conn.crecv(buf, 1024)
message += string( byteptr(buf), m )
if message.len > MAX_HTTP_POST_SIZE { break }
if message.len > max_http_post_size { break }
if n == m { break }
}
return message