-
Notifications
You must be signed in to change notification settings - Fork 654
/
Copy pathruntime.go
64 lines (54 loc) · 1.46 KB
/
runtime.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package runtime
import (
"fmt"
jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/application"
v8 "github.com/yaoapp/gou/runtime/v8"
"github.com/yaoapp/yao/config"
)
// Start v8 runtime
func Start(cfg config.Config) error {
debug := false
if cfg.Mode == "development" {
debug = true
}
option := &v8.Option{
MinSize: cfg.Runtime.MinSize,
MaxSize: cfg.Runtime.MaxSize,
HeapSizeLimit: cfg.Runtime.HeapSizeLimit,
HeapAvailableSize: cfg.Runtime.HeapAvailableSize,
HeapSizeRelease: cfg.Runtime.HeapSizeRelease,
Precompile: cfg.Runtime.Precompile,
DataRoot: cfg.DataRoot,
Mode: cfg.Runtime.Mode,
DefaultTimeout: cfg.Runtime.DefaultTimeout,
ContextTimeout: cfg.Runtime.ContextTimeout,
Import: cfg.Runtime.Import,
Debug: debug,
}
// Read the tsconfig.json
if cfg.Runtime.Import && application.App != nil {
if exist, _ := application.App.Exists("tsconfig.json"); exist {
var tsconfig v8.TSConfig
raw, err := application.App.Read("tsconfig.json")
if err != nil {
return fmt.Errorf("tsconfig.json is not a valid json file %s", err)
}
err = jsoniter.Unmarshal(raw, &tsconfig)
if err != nil {
return fmt.Errorf("tsconfig.json is not a valid json file %s", err)
}
option.TSConfig = &tsconfig
}
}
err := v8.Start(option)
if err != nil {
return err
}
return nil
}
// Stop v8 runtime
func Stop() error {
v8.Stop()
return nil
}