Skip to content

Commit a8f9da8

Browse files
author
André R. de Miranda
authored
Support to WebAssembly (#174)
Signed-off-by: André R. de Miranda <andre@galgo.tech>
1 parent 2b1db96 commit a8f9da8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

model/util.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"path/filepath"
2525
"reflect"
26+
"runtime"
2627
"strings"
2728
"sync/atomic"
2829
"time"
@@ -139,6 +140,10 @@ func loadExternalResource(url string) (b []byte, err error) {
139140
}
140141

141142
func getBytesFromFile(path string) ([]byte, error) {
143+
if WebAssembly() {
144+
return nil, fmt.Errorf("unsupported open file")
145+
}
146+
142147
// if path is relative, search in include paths
143148
if !filepath.IsAbs(path) {
144149
paths := IncludePaths()
@@ -288,11 +293,15 @@ func unmarshalObject[U any](parameterName string, data []byte, value *U) error {
288293
var defaultIncludePaths atomic.Value
289294

290295
func init() {
296+
// No execute set include path to suport webassembly
297+
if WebAssembly() {
298+
return
299+
}
300+
291301
wd, err := os.Getwd()
292302
if err != nil {
293303
panic(err)
294304
}
295-
296305
SetIncludePaths([]string{wd})
297306
}
298307

@@ -311,3 +320,7 @@ func SetIncludePaths(paths []string) {
311320

312321
defaultIncludePaths.Store(paths)
313322
}
323+
324+
func WebAssembly() bool {
325+
return runtime.GOOS == "js" && runtime.GOARCH == "wasm"
326+
}

0 commit comments

Comments
 (0)