Skip to content

Host functions

๐Ÿšง this is a work in progress, each host function will be detailed with samples.

The Capsule applications (and the Capsule HDK) offer some capabilities to the wasm modules by providing some "host functions".

This is the list of the available host functions:

  • Print a message: Print(message string), usage: capsule.Print("๐Ÿ‘‹ Hello Worls ๐ŸŒ")
  • Log a message: Log(message string), usage: capsule.Log("๐Ÿ˜ก something wrong")
  • Get the value of an environment variable: GetEnv(variableName string) string, usage: capsule.GetEnv("MESSAGE")
  • Read a text file: ReadFile(filePath string) ([]byte, error), usage: data, err := capsule.ReadFile("./hello.txt")
  • Write a content to a text file: WriteFile(filePath string, content []byte) error, usage: err := capsule.WriteFile("./hello.txt", []byte("๐Ÿ‘‹ Hello World! ๐ŸŒ"))
  • Make an HTTP request: HTTP(request HTTPRequest) (HTTPResponse, error), usage: respJSON, err := capsule.HTTP(capsule.HTTPRequest{}), see the "hey-people" sample
  • Memory Cache: see the "mem-db" sample
  • CacheSet(key string, value []byte) []byte
  • CacheGet(key string) ([]byte, error)
  • CacheDel(key string) []byte
  • CacheKeys(filter string) ([]string, error) (right now, you can only use this filter: *)
  • Redis Cache: see the "redis-db" sample
  • RedisSet(key string, value []byte) ([]byte, error)
  • RedisGet(key string) ([]byte, error)
  • RedisDel(key string) ([]byte, error)
  • RedisKeys(filter string) ([]string, error)