mirror of
https://github.com/vlang/v.git
synced 2025-09-16 16:02:29 +03:00
all: change optional to result of io (#16075)
This commit is contained in:
parent
6e46933c55
commit
f6844e9766
187 changed files with 1885 additions and 1874 deletions
|
@ -4,7 +4,7 @@ import net.urllib
|
|||
import net.http
|
||||
|
||||
// Parsing function attributes for methods and path.
|
||||
fn parse_attrs(name string, attrs []string) ?([]http.Method, string) {
|
||||
fn parse_attrs(name string, attrs []string) !([]http.Method, string) {
|
||||
if attrs.len == 0 {
|
||||
return [http.Method.get], '/$name'
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ fn parse_query_from_url(url urllib.URL) map[string]string {
|
|||
return query
|
||||
}
|
||||
|
||||
fn parse_form_from_request(request http.Request) ?(map[string]string, map[string][]http.FileData) {
|
||||
fn parse_form_from_request(request http.Request) !(map[string]string, map[string][]http.FileData) {
|
||||
mut form := map[string]string{}
|
||||
mut files := map[string][]http.FileData{}
|
||||
if request.method in methods_with_form {
|
||||
|
|
|
@ -42,7 +42,7 @@ pub fn new_connection(conn &net.TcpConn) &SSEConnection {
|
|||
}
|
||||
|
||||
// sse_start is used to send the start of a Server Side Event response.
|
||||
pub fn (mut sse SSEConnection) start() ? {
|
||||
pub fn (mut sse SSEConnection) start() ! {
|
||||
sse.conn.set_write_timeout(sse.write_timeout)
|
||||
mut start_sb := strings.new_builder(512)
|
||||
start_sb.write_string('HTTP/1.1 200')
|
||||
|
@ -58,7 +58,7 @@ pub fn (mut sse SSEConnection) start() ? {
|
|||
|
||||
// send_message sends a single message to the http client that listens for SSE.
|
||||
// It does not close the connection, so you can use it many times in a loop.
|
||||
pub fn (mut sse SSEConnection) send_message(message SSEMessage) ? {
|
||||
pub fn (mut sse SSEConnection) send_message(message SSEMessage) ! {
|
||||
mut sb := strings.new_builder(512)
|
||||
if message.id != '' {
|
||||
sb.write_string('id: $message.id\n')
|
||||
|
@ -73,5 +73,5 @@ pub fn (mut sse SSEConnection) send_message(message SSEMessage) ? {
|
|||
sb.write_string('retry: $message.retry\n')
|
||||
}
|
||||
sb.write_string('\n')
|
||||
sse.conn.write(sb)?
|
||||
sse.conn.write(sb)!
|
||||
}
|
||||
|
|
|
@ -331,7 +331,7 @@ pub fn (mut ctx Context) set_cookie_with_expire_date(key string, val string, exp
|
|||
}
|
||||
|
||||
// Gets a cookie by a key
|
||||
pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
|
||||
pub fn (ctx &Context) get_cookie(key string) !string { // TODO refactor
|
||||
mut cookie_header := ctx.get_header('cookie')
|
||||
if cookie_header == '' {
|
||||
cookie_header = ctx.get_header('Cookie')
|
||||
|
@ -391,7 +391,7 @@ pub struct RunParams {
|
|||
// run_at - start a new VWeb server, listening only on a specific address `host`, at the specified `port`
|
||||
// Example: vweb.run_at(new_app(), vweb.RunParams{ host: 'localhost' port: 8099 family: .ip }) or { panic(err) }
|
||||
[manualfree]
|
||||
pub fn run_at<T>(global_app &T, params RunParams) ? {
|
||||
pub fn run_at<T>(global_app &T, params RunParams) ! {
|
||||
if params.port <= 0 || params.port > 65535 {
|
||||
return error('invalid port number `$params.port`, it should be between 1 and 65535')
|
||||
}
|
||||
|
@ -714,11 +714,11 @@ pub fn not_found() Result {
|
|||
return Result{}
|
||||
}
|
||||
|
||||
fn send_string(mut conn net.TcpConn, s string) ? {
|
||||
fn send_string(mut conn net.TcpConn, s string) ! {
|
||||
$if trace_response ? {
|
||||
eprintln('> send_string:\n$s\n')
|
||||
}
|
||||
conn.write(s.bytes())?
|
||||
conn.write(s.bytes())!
|
||||
}
|
||||
|
||||
// Do not delete.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue