-
Notifications
You must be signed in to change notification settings - Fork 3
/
runtime.go
46 lines (36 loc) · 876 Bytes
/
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
package blox
import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
)
type Runtime struct {
CueContext *cue.Context
Database cue.Value
}
// NewRuntime creates a new runtime engine
func NewRuntime() (*Runtime, error) {
cueContext := cuecontext.New()
cueValue := cueContext.CompileString("")
if cueValue.Err() != nil {
return nil, cueValue.Err()
}
runtime := &Runtime{
CueContext: cueContext,
Database: cueValue,
}
return runtime, nil
}
// NewRuntimeWithBase creates a new runtime engine
// with the cue provided in `base` as the initial cue values
func NewRuntimeWithBase(base string) (*Runtime, error) {
cueContext := cuecontext.New()
cueValue := cueContext.CompileString(base)
if cueValue.Err() != nil {
return nil, cueValue.Err()
}
runtime := &Runtime{
CueContext: cueContext,
Database: cueValue,
}
return runtime, nil
}