Skip to content

Commit

Permalink
chore: Updating README & Code attribution
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Fontes <[email protected]>
  • Loading branch information
lxfontes committed Oct 1, 2024
1 parent a5b00da commit cfa5a27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Import `go.wasmcloud.dev/component` in your Go module.
Import the SDK WIT. In `wit/deps.toml`:

```
wasmcloud-component = "https://github.com/wasmCloud/component-sdk-go/archive/<TBD>.tar.gz"
wasmcloud-component = "https://github.com/wasmCloud/component-sdk-go/archive/main.tar.gz"
```

Run `wit-deps` to update your wit dependencies.
Expand All @@ -28,6 +28,8 @@ And in your world definition:
include wasmcloud:component/imports;
```

# Adapters

## net/wasihttp

The `wasihttp` package provides an implementation of `http.Handler` backed by `wasi:http`, as well as a `http.RoundTripper` backed by `wasi:http`.
Expand All @@ -48,7 +50,7 @@ func httpServe(w http.ResponseWriter, *r http.Request) {

func init() {
// request will be fulfilled via wasi:http/incoming-handler
wasihttp.Handle("/", httpServe)
wasihttp.HandleFunc("/", httpServe)
}
```

Expand Down Expand Up @@ -87,3 +89,11 @@ logger.Info("Hello", slog.String("planet", "Earth"))
```

See `wasilog.Options` for log level & other configuration options.

## Community

Similar projects:

- [rajatjindal/wasi-go-sdk](https://github.com/rajatjindal/wasi-go-sdk)
- [dev-wasm/dev-wasm-go](https://github.com/dev-wasm/dev-wasm-go)
- [Mossaka/hello-wasi-http-tinygo](https://github.com/Mossaka/hello-wasi-http-tinygo)
2 changes: 2 additions & 0 deletions net/wasihttp/adapter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package wasihttp

// Refactored from https://github.com/rajatjindal/wasi-go-sdk/tree/d3e8665bef9fbf0794ad14f7114a9882e0d983c3/pkg/wasihttp

import (
"fmt"
"io"
Expand Down
7 changes: 6 additions & 1 deletion net/wasihttp/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func (r *Transport) RoundTrip(incomingRequest *http.Request) (*http.Response, er

outRequest.SetAuthority(cm.Some(incomingRequest.Host))
outRequest.SetMethod(toWasiMethod(incomingRequest.Method))
outRequest.SetPathWithQuery(cm.Some(incomingRequest.URL.Path + "?" + incomingRequest.URL.Query().Encode()))

pathWithQuery := incomingRequest.URL.Path
if incomingRequest.URL.RawQuery != "" {
pathWithQuery = pathWithQuery + "?" + incomingRequest.URL.Query().Encode()
}
outRequest.SetPathWithQuery(cm.Some(pathWithQuery))

switch incomingRequest.URL.Scheme {
case "http":
Expand Down

0 comments on commit cfa5a27

Please sign in to comment.