diff --git a/README.md b/README.md index 64a4ffa..9831d4a 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ struct ExampleResponse { email: Str } -async func handle(req: http.Request, resp: mut http.Response) { +async fn handle(req: http.Request, resp: mut http.Response) { log.info("request: ", req.body) let response_data = ExampleResponse{id: 4, name: "Steven", email: "swerbenjagermanjensen@example.com"} await resp.set_status(200) await resp.write(json.encode(response_data)) } -async func main(args: Array) Int32 { +async fn main(args: Array) Int32 { let router = http.Router("").add_route("/myroute", handle) http_server = http.Server("localhost", 8080, router) let err := await http_server.server_forever() @@ -66,11 +66,11 @@ Methods on a struct must specify if they mutate the struct. ``` impl Dict { - func insert(self: mut Dict, key: Key, value: Value) { + fn insert(self: mut Dict, key: Key, value: Value) { // mutate self here } - func get(self: Dict, key: Key) Optional { + fn get(self: Dict, key: Key) Optional { // no need for `mut` } } @@ -86,18 +86,18 @@ Context is an exceptionally useful feature in golang, but a common complaint is The boring standard library solves this by using parametric polymorphism. Context is by default an empty object passed through the chain, and each function/set of context parameters is an additional trait condition applied at compile time. ``` -type HTTPRequest = async func(Ctx, http.Request, mut http.Response) +type HTTPRequest = async fn(Ctx, http.Request, mut http.Response) -pub func tracing_middleware(handler: HTTPRequest) HTTPRequest { - return async func(ctx: Ctx, req: http.Request, resp: mut http.Response) { +pub fn tracing_middleware(handler: HTTPRequest) HTTPRequest { + return async fn(ctx: Ctx, req: http.Request, resp: mut http.Response) { with tracing.Span(ctx, "request_duration") { await handler(ctx, req, resp) } } } -pub func auth_middleware(handler: HTTPRequest, scope: Str) HTTPRequest { - return async func(ctx: Ctx, req: http.Request, resp: mut http.Response) { +pub fn auth_middleware(handler: HTTPRequest, scope: Str) HTTPRequest { + return async fn(ctx: Ctx, req: http.Request, resp: mut http.Response) { if ctx.has_scope(scope) { await handler(ctx, req, resp) } @@ -106,8 +106,8 @@ pub func auth_middleware(handler: HTTPRequest, scope: Str) HTTPR } } -pub func cancel_middleware(handler: HTTPRequest) HTTPRequest { - return async func(ctx: Ctx, req: http.Request, resp: mut http.Response) { +pub fn cancel_middleware(handler: HTTPRequest) HTTPRequest { + return async fn(ctx: Ctx, req: http.Request, resp: mut http.Response) { if !(await ctx.is_cancelled()) { // check cancel token await handler(ctx, req, resp) }