Skip to content

Commit ebc276f

Browse files
authored
feat: receiving WATER dir as an option and creating required directories (#79)
1 parent ffdd8a0 commit ebc276f

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

option/water.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ type WATEROutboundOptions struct {
2828
// DownloadTimeout specifies how much time the downloader should wait
2929
// until it cancel and try to fetch from another URL
3030
DownloadTimeout string `json:"download_timeout"`
31-
// WASMStorageDir specifies which directory should store the WASM files
32-
WASMStorageDir string `json:"water_dir"`
33-
// WazeroCompilationCacheDir specifies which directory should be used for storing
34-
// Wazero cache
35-
WazeroCompilationCacheDir string `json:"wazero_compilation_cache_dir"`
31+
// Dir specifies which directory we should use for storing WATER related
32+
// files
33+
Dir string `json:"water_dir"`
3634
// Config is a optional config that will be sent to the WASM file.
3735
Config map[string]any `json:"config,omitempty"`
3836
// SkipHandshake is used when the WATER module deals with the handshake

protocol/water/outbound.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net"
88
"net/http"
99
"os"
10+
"path/filepath"
1011
"strconv"
1112
"sync"
1213
"time"
@@ -55,22 +56,20 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
5556
return nil, err
5657
}
5758

58-
if options.WASMStorageDir == "" {
59-
return nil, E.New("provided an empty storage directory for WASM files")
59+
if options.Dir == "" {
60+
return nil, E.New("provided an empty storage directory for WATER files")
6061
}
6162

62-
if options.WazeroCompilationCacheDir == "" {
63-
return nil, E.New("provided an empty storage directory for wazero compilation cache")
64-
}
65-
66-
for _, dir := range []string{options.WASMStorageDir, options.WazeroCompilationCacheDir} {
63+
wasmDir := filepath.Join(options.Dir, "wasm_files")
64+
wazeroCompilationDir := filepath.Join(options.Dir, "wazero_compilation_cache")
65+
for _, dir := range []string{wasmDir, wazeroCompilationDir} {
6766
if err := os.MkdirAll(dir, 0755); err != nil {
6867
return nil, err
6968
}
7069
}
7170

7271
slogLogger := slog.New(L.NewLogHandler(logger))
73-
vc := waterVC.NewWaterVersionControl(options.WASMStorageDir, slogLogger)
72+
vc := waterVC.NewWaterVersionControl(wasmDir, slogLogger)
7473
d, err := waterDownloader.NewWASMDownloader(options.WASMAvailableAt, &http.Client{Timeout: timeout})
7574
if err != nil {
7675
return nil, E.New("failed to create WASM downloader", err)
@@ -95,7 +94,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
9594

9695
// We're creating the compilation cache dir and setting the global value so during runtime
9796
// it won't need to create one at a temp directory
98-
compilationCache, err := wazero.NewCompilationCacheWithDir(options.WazeroCompilationCacheDir)
97+
compilationCache, err := wazero.NewCompilationCacheWithDir(wazeroCompilationDir)
9998
if err != nil {
10099
return nil, err
101100
}

0 commit comments

Comments
 (0)