Skip to content

Commit 73d82ce

Browse files
Upgrade http package and clean Roc style
1 parent b0b62d9 commit 73d82ce

40 files changed

Lines changed: 229 additions & 222 deletions

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Run this example server with `$ roc examples/hello-web.roc` and go to `http://lo
2222
```roc
2323
app [Model, program] {
2424
pf: platform "<latest release URL from https://github.com/roc-lang/basic-webserver/releases/latest>",
25-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
25+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
2626
}
2727
2828
import pf.Http
@@ -34,20 +34,19 @@ Model : {}
3434
3535
program = { init!, respond! }
3636
37-
init! : {} => Try(Model, [Exit(I64), ..])
38-
init! = |{}| Ok({})
37+
init! : () => Try(Model, [Exit(I64), ..])
38+
init! = || Ok({})
3939
4040
respond! : Http.Request, Model => Try(Http.Response, [ServerErr(Str), ..])
4141
respond! = |req, _model| {
42-
millis = Utc.to_millis_since_epoch(Utc.now!({}))
42+
millis = Utc.to_millis_since_epoch(Utc.now!())
4343
44-
_ =
45-
Stdout.line!("${millis.to_str()} ${Str.inspect(req.method())} ${req.uri()}")
44+
Stdout.line!("${millis.to_str()} ${Str.inspect(req.method())} ${req.uri()}")
4645
? |err| ServerErr("Failed to log request: ${Str.inspect(err)}")
4746
4847
response =
4948
Response.from_status(200)
50-
.with_headers(Http.header_tuples([{ name: "Content-Type", value: "text/html; charset=utf-8" }]))
49+
.with_headers([{ name: "Content-Type", value: "text/html; charset=utf-8" }])
5150
.with_body(Str.to_utf8("<b>Hello from server</b></br>"))
5251
5352
Ok(response)

examples/command.roc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.Http
@@ -28,13 +28,13 @@ init! = || {
2828
.args(["Hi"])
2929
.exec_output!()?
3030

31-
_ = Stdout.line!("${Str.inspect(cmd_output)}")
31+
Stdout.line!("${Str.inspect(cmd_output)}")?
3232

3333
# To run a command with environment variables.
3434
Cmd.new("env")
3535
.clear_envs() # You probably don't need to clear all other environment variables, this is just an example.
3636
.env("FOO", "BAR")
37-
.envs([("BAZ", "DUCK"), ("XYZ", "ABC")]) # Set multiple environment variables at once with `envs`
37+
.envs([{ name: "BAZ", value: "DUCK" }, { name: "XYZ", value: "ABC" }]) # Set multiple environment variables at once with `envs`
3838
.args(["-v"])
3939
.exec_cmd!()?
4040

@@ -45,7 +45,7 @@ init! = || {
4545
.args(["non_existent.txt"])
4646
.exec_exit_code!()?
4747

48-
_ = Stdout.line!("Exit code: ${exit_code.to_str()}")
48+
Stdout.line!("Exit code: ${exit_code.to_str()}")?
4949
5050
# To execute and capture the output (stdout and stderr) in the original form as bytes without inheriting your terminal.
5151
# Prefer using `exec_output!`.
@@ -54,15 +54,15 @@ init! = || {
5454
.args(["Hi"])
5555
.exec_output_bytes!()?
5656
57-
_ = Stdout.line!("${Str.inspect(cmd_output_bytes)}")
57+
Stdout.line!("${Str.inspect(cmd_output_bytes)}")?
5858

5959
Ok({})
6060
}
6161

6262
match result() {
6363
Ok(_) => Ok({})
6464
Err(err) => {
65-
_ = Stderr.line!("Error running commands: ${Str.inspect(err)}")
65+
Stderr.line!("Error running commands: ${Str.inspect(err)}") ?? {}
6666
Err(Exit(1))
6767
}
6868
}

examples/dir.roc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.Stdout
@@ -31,25 +31,25 @@ init! = || {
3131
# List the contents of a directory
3232
paths = Dir.list!("nested-dir")?
3333

34-
paths_str = Str.join_with(List.map(paths, Path.display), ", ")
34+
paths_str = Str.join_with(paths.map(Path.display), ", ")
3535
36-
_ = Stdout.line!("The paths in nested-dir are: ${paths_str}")
36+
Stdout.line!("The paths in nested-dir are: ${paths_str}")?
3737
3838
# Delete an empty directory
3939
Dir.delete_empty!("empty-dir")?
4040
4141
# Delete all directories recursively
4242
Dir.delete_all!("nested-dir")?
4343
44-
_ = Stdout.line!("Success!")
44+
Stdout.line!("Success!")?
4545
4646
Ok({})
4747
}
4848
4949
match result() {
5050
Ok(_) => Ok({})
5151
Err(err) => {
52-
_ = Stderr.line!("Error during directory operations: ${Str.inspect(err)}")
52+
Stderr.line!("Error during directory operations: ${Str.inspect(err)}") ?? {}
5353
Err(Exit(1))
5454
}
5555
}

examples/echo.roc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.Http
@@ -20,6 +20,7 @@ init! = || Ok({})
2020

2121
respond! : Http.Request, Model => Try(Http.Response, [ServerErr(Str), ..])
2222
respond! = |req, _model| {
23-
_ = Stdout.line!("${Str.inspect(req.method())} ${req.uri()}")
23+
Stdout.line!("${Str.inspect(req.method())} ${req.uri()}")
24+
? |err| ServerErr("Failed to log request: ${Str.inspect(err)}")
2425
Ok(Response.from_status(200).with_body(req.body()))
2526
}

examples/env.roc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.Env

examples/error-handling.roc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This example demonstrates error handling and fetching content from another website.
22
app [Model, program] {
33
pf: platform "../platform/main.roc",
4-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
4+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
55
}
66

77
import pf.Stdout

examples/file-accessed-modified-created-time.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.Stdout
@@ -34,7 +34,7 @@ init! = || {
3434
match result() {
3535
Ok(_) => Ok({})
3636
Err(err) => {
37-
_ = Stderr.line!("Error reading file time metadata: ${Str.inspect(err)}")
37+
Stderr.line!("Error reading file time metadata: ${Str.inspect(err)}") ?? {}
3838
Err(Exit(1))
3939
}
4040
}

examples/file-permissions.roc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.Stdout
@@ -32,7 +32,7 @@ init! = || {
3232
match result() {
3333
Ok(_) => Ok({})
3434
Err(err) => {
35-
_ = Stderr.line!("Error reading file permissions: ${Str.inspect(err)}")
35+
Stderr.line!("Error reading file permissions: ${Str.inspect(err)}") ?? {}
3636
Err(Exit(1))
3737
}
3838
}

examples/file-read-buffered.todoroc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ respond! = |_, model|
4040
process_line! : File.Reader, ReadSummary => Result ReadSummary _
4141
process_line! = |reader, { lines_read, bytes_read }|
4242
when File.read_line!(reader) is
43-
Ok(bytes) if List.len(bytes) == 0 ->
43+
Ok(bytes) if bytes.len() == 0 ->
4444
Ok({ lines_read, bytes_read })
4545

4646
Ok(bytes) ->
4747
process_line!(
4848
reader,
4949
{
5050
lines_read: lines_read + 1,
51-
bytes_read: bytes_read + (List.len(bytes) |> Num.int_cast),
51+
bytes_read: bytes_read + (bytes.len() |> Num.int_cast),
5252
},
5353
)
5454

examples/file-read.roc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app [Model, program] {
22
pf: platform "../platform/main.roc",
3-
http: "https://github.com/roc-lang/http/releases/download/0.1/6LcdNq2r7xTBwj972ecYWUkMWobJr94yL2NyJpHRAXap.tar.zst",
3+
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
44
}
55

66
import pf.File

0 commit comments

Comments
 (0)