This repository has been archived by the owner on Feb 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b6dc33
commit 27dd624
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module pack/name | ||
|
||
go 1.20 | ||
|
||
require github.com/golemcloud/golem-go v1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/golemcloud/golem-go v1.1.0 h1:By+OBuRu4c3WTuf2OKh71yY7rgOyLXzUgr7Y+98BjGk= | ||
github.com/golemcloud/golem-go v1.1.0/go.mod h1:VLL22qVo5R2+jGLO43tLPpPjf2WrA6B7GQoqXKnSODo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Schema for IDEA: | ||
# $schema: https://schema.golem.cloud/app/golem/1.1.1/golem.schema.json | ||
# Schema for vscode-yaml | ||
# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.1/golem.schema.json | ||
|
||
tempDir: build/golem-temp | ||
components: | ||
pack:name: | ||
sourceWit: wit | ||
generatedWit: wit-generated | ||
componentWasm: build/adapted-components/component_name.wasm | ||
linkedWasm: build/linked-components/component_name_linked.wasm | ||
build: | ||
- command: wit-bindgen tiny-go --rename-package binding --out-dir binding ./wit-generated | ||
rmdirs: | ||
- binding | ||
mkdirs: | ||
- binding | ||
sources: | ||
- wit-generated | ||
targets: | ||
- binding | ||
- command: tinygo build -target=wasi -tags=purego -o build/components/component_name.wasm main.go | ||
mkdirs: | ||
- build/components | ||
sources: | ||
- component_name | ||
- main.go | ||
targets: | ||
- build/components/component_name.wasm | ||
- command: wasm-tools component embed wit-generated build/components/component_name.wasm --output build/embedded-components/component_name.wasm | ||
mkdirs: | ||
- build/embedded-components | ||
sources: | ||
- wit-generated | ||
- build/components/component_name.wasm | ||
targets: | ||
- build/embedded-components/component_name.wasm | ||
- command: wasm-tools component new build/embedded-components/component_name.wasm -o build/adapted-components/component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm | ||
mkdirs: | ||
- build/adapted-components | ||
sources: | ||
- adapters/tier1/wasi_snapshot_preview1.wasm | ||
- build/embedded-components/component_name.wasm | ||
targets: | ||
- build/adapted-components/component_name.wasm | ||
clean: | ||
- build | ||
- binding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"pack/name/binding" | ||
) | ||
|
||
// Helper type aliases to make code more readable | ||
type HttpRequest = binding.ExportsWasiHttp0_2_0_IncomingHandlerIncomingRequest | ||
type HttpResponseOut = binding.ExportsWasiHttp0_2_0_IncomingHandlerResponseOutparam | ||
type HttpOutgoingResponse = binding.WasiHttp0_2_0_TypesOutgoingResponse | ||
type HttpError = binding.WasiHttp0_2_0_TypesErrorCode | ||
|
||
func init() { | ||
binding.SetExportsWasiHttp0_2_0_IncomingHandler(&ComponentNameImpl{}) | ||
} | ||
|
||
type ComponentNameImpl struct {} | ||
|
||
// Implementation of the exported interface | ||
|
||
func (e *ComponentNameImpl) Handle(request HttpRequest, responseOut HttpResponseOut) { | ||
// Construct HttpResponse to send back | ||
headers := binding.NewFields() | ||
httpResponse := binding.NewOutgoingResponse(headers) | ||
httpResponse.SetStatusCode(200) | ||
httpResponse.Body().Unwrap().Write().Unwrap().BlockingWriteAndFlush([]uint8("Hello from Go!\n")).Unwrap() | ||
|
||
// Send HTTP response | ||
okResponse := binding.Ok[HttpOutgoingResponse, HttpError](httpResponse) | ||
binding.StaticResponseOutparamSet(responseOut, okResponse) | ||
} | ||
|
||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"description": "A Golem worker implementing wasi:http/incoming-handler. For use with the http-handler api gateway binding type", | ||
"requiresAdapter": true, | ||
"adapterTarget": "adapters", | ||
"requiresGolemHostWIT": true, | ||
"requiresWASI": true, | ||
"instructions": "INSTRUCTIONS-app", | ||
"exclude": [ | ||
"wit-generated", | ||
"build", | ||
"main.wasm" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package pack:name; | ||
|
||
// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax | ||
// See https://github.com/WebAssembly/wasi-http for an introduction to wasi-http | ||
|
||
world component-name { | ||
// Always required due to a limitation of the bindings generation in componentize-py. | ||
// This import will fail if removed https://github.com/bytecodealliance/componentize-py/blob/c50822c825b4333ff41a0ea3cd9e0c9bc3df49da/bundled/poll_loop.py#L15 | ||
import wasi:http/outgoing-handler@0.2.0; | ||
|
||
export wasi:http/incoming-handler@0.2.0; | ||
} |