Key Value API
1
4fbf02fc-0329-4291-aac3-0143969167c4
Promise API
2
4fbf02fc-0329-4291-aac3-0143969167c4
Worker API
8
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Token API
7
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Template API
6
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Project policy API
5
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Project grant API
4
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Project API
3
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Login API
2
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Account API
1
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Breaking changes August 2023
1
726cfb0b-bffe-41ba-98b4-94069569ec3c
Overview
0
726cfb0b-bffe-41ba-98b4-94069569ec3c
Tier 4 languages
4
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
Python
4
54bda586-0bf3-430e-93e5-6d8c578372bd
Overview
0
ac8f610e-7e8f-465d-9e32-4b6ae0aba3b5
Overview
0
0f58ad57-8cb7-4a64-8aed-c7bea90c37f9
Overview
0
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
Overview
0
54bda586-0bf3-430e-93e5-6d8c578372bd
Overview
0
9b92ca64-009f-47e8-9457-b544f786d8af
Quickstart
2
1d167981-dd90-40ab-8023-3b2013ceb5c5
Overview
0
1aa11fd4-1dcf-4c87-8b46-5c15ca815d61
Overview
0
4fbf02fc-0329-4291-aac3-0143969167c4
Overview
0
d0be080a-56f4-481a-91d3-ba7d30c144f4
Common tooling
1
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
C
3
54bda586-0bf3-430e-93e5-6d8c578372bd
Go
2
54bda586-0bf3-430e-93e5-6d8c578372bd
Grain
3
9b92ca64-009f-47e8-9457-b544f786d8af
Swift
1
9b92ca64-009f-47e8-9457-b544f786d8af
C#
3
9b92ca64-009f-47e8-9457-b544f786d8af
Zig
2
9b92ca64-009f-47e8-9457-b544f786d8af
Rust
1
54bda586-0bf3-430e-93e5-6d8c578372bd
Overview
0
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Overview
0
62133a19-c114-4a29-a74b-f986d118e157
Why Golem?
1
1d167981-dd90-40ab-8023-3b2013ceb5c5
Overview
0
1d167981-dd90-40ab-8023-3b2013ceb5c5
API Gateway
308adf1f-525e-460e-81c9-6ea00d1dbca4
d0be080a-56f4-481a-91d3-ba7d30c144f4
4
Release notes
726cfb0b-bffe-41ba-98b4-94069569ec3c
d0be080a-56f4-481a-91d3-ba7d30c144f4
9
Component interface
ac8f610e-7e8f-465d-9e32-4b6ae0aba3b5
d0be080a-56f4-481a-91d3-ba7d30c144f4
7
Getting Started
1d167981-dd90-40ab-8023-3b2013ceb5c5
d0be080a-56f4-481a-91d3-ba7d30c144f4
1
Building Components
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
d0be080a-56f4-481a-91d3-ba7d30c144f4
2
Tier 2 languages
54bda586-0bf3-430e-93e5-6d8c578372bd
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
2
Promises
62133a19-c114-4a29-a74b-f986d118e157
d0be080a-56f4-481a-91d3-ba7d30c144f4
3
Tier 3 languages
9b92ca64-009f-47e8-9457-b544f786d8af
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
3
Golem CLI
1aa11fd4-1dcf-4c87-8b46-5c15ca815d61
d0be080a-56f4-481a-91d3-ba7d30c144f4
4
REST API
fc0b5887-cca5-4261-b6b7-73711f6f23b0
d0be080a-56f4-481a-91d3-ba7d30c144f4
5
Runtime API
4fbf02fc-0329-4291-aac3-0143969167c4
d0be080a-56f4-481a-91d3-ba7d30c144f4
6
FAQ
0f58ad57-8cb7-4a64-8aed-c7bea90c37f9
d0be080a-56f4-481a-91d3-ba7d30c144f4
7

Go

54bda586-0bf3-430e-93e5-6d8c578372bd

TinyGo can compile Go code into core WASM modules and has limited support to WASI. Support for TinyGo-generated WASM files is limited in Golem right now but it can work in some cases.

Install it on OSX via brew:

brew tap tinygo-org/tools

brew install tinygo

You also have to install everything as described in Common tooling.

The easiest way to get started once the tooling is installed is to use the golem new command as described in the Quickstart.

If you prefer to do it from scratch, first we have to create a now Go module:

go mod init golem.com/tinygo_example

Then create a wit directory with a main.wit describing your template, optionally importing WASI or Golem specific extra interfaces (put them in wit/deps, copied from golem-cli's package):

package my:template



world tinygo-example {

import wasi:poll/poll

import wasi:io/streams

import wasi:http/types

import wasi:http/outgoing-handler



export example1: func(s: string) -> s32

}

The next step is generating bindings with wit-bindgen:

wit-bindgen tiny-go --out-dir tinygo_example ./wit

And write your template in the module’s main package (main.go in the root):

package main



import (

"fmt"

"math/rand"

"time"



"golem.com/tinygo_example/tinygo_example"

)



func init() {

a := TinygoExampleImpl{}

tinygo_example.SetTinygoExample(a)

}



type TinygoExampleImpl struct {

}



func (e TinygoExampleImpl) Example1(s string) int32 {

fmt.Println(s)



s1 := rand.NewSource(time.Now().UnixNano())

r1 := rand.New(s1)

v1 := r1.Int31()

currentTime := time.Now()



fmt.Println("test", currentTime.Year(), v1)

return v1

}



func main() {

}

It’s important to have an (empty) main function as well.

Finally compile the go source to a core WASM module:

tinygo build -target=wasi -o main.wasm main.go

The resulting WASM file in main.wasm is just a WASM module, not ready to be used with Golem.

First we need to embed the WIT interface definition with wasm-tools:

wasm-tools component embed ./wit main.wasm --output main.embed.wasm

The resulting WASM is still not a WASM component, but it has the binary encoding of the WIT file in a custom section.

The final step is converting the module in a WASM component, including mapping its WASI Preview1 imports into WASI Preview2 imports.

This is done with wasm-tools too:

wasm-tools component new main.embed.wasm -o template.wasm --adapt adapters/tier2/wasi_snapshot_preview1.wasm

The wasi_snapshot_preview1.wasm describes the mapping from WASI Preview1 to Preview2. You must use the version of this file packaged together with golem-cli.

💡
Make sure you use the tier2 adapter from the golem package!

The resulting template.wasm is ready to be used with Golem.

HTTP

We provide a Go package for integration Go’s http package with the WASI-HTTP interface provided by Golem.

To use this, first add the package to your module by

go get github.com/zivergetech/go-wasi-http@main

Then import and set the RoundTrip implementation provided by this package:

import (

"net/http"

go_wasi_http "github.com/zivergetech/go-wasi-http/roundtrip"

)



// ...



http.DefaultClient.Transport = go_wasi_http.WasiHttpTransport{}

Then use the http package or any other libraries built on top of that to communicate with external services:

postBody, _ := json.Marshal(ExampleRequest{

Name: "Something",

Amount: 42,

Comments: []string{"Hello", "World"},

})

resp, err := http.Post("http://localhost:9999/post-example", "application/json", bytes.NewBuffer(postBody))

if err != nil {

return fmt.Sprintln(err)

}

body, err := ioutil.ReadAll(resp.Body)

if err != nil {

return fmt.Sprintln(err)

}



var response ExampleResponse

err = json.Unmarshal(body, &response)

if err != nil {

return fmt.Sprintln(err)

}