-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.load.go
36 lines (31 loc) · 1.01 KB
/
main.load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"context"
"errors"
"log"
"github.com/bots-garden/capsule/capsule-http/handlers"
"github.com/bots-garden/capsule/capsule-http/tools"
"github.com/tetratelabs/wazero"
)
// LoadWasmFile -> load the wasm file (or download it)
// the function exits if the wasm file is not present
func LoadWasmFile(ctx context.Context, flags CapsuleFlags, runtime wazero.Runtime) ([]byte, error) {
if flags.wasm != "" {
wasmFile, err := tools.GetWasmFile(flags.wasm, flags.url, flags.authHeaderName, flags.authHeaderValue)
if err != nil {
log.Println("❌📝 Error while loading the wasm file", err)
return nil, err
}
// Save the wasmFile to memory
handlers.StoreWasmFile(wasmFile)
return wasmFile, nil
}
// the wasm file is not mandatory in faas mode
// otherwise it's an error
if flags.faas != true {
log.Println("❌📝 Error while loading the wasm file (empty)")
return nil, errors.New("empty wasm file")
}
// when flags.faas is true, the wasm file is not mandatory
return nil, nil
}