fx/stream.go

43 lines
786 B
Go
Raw Normal View History

2022-04-29 21:17:39 +00:00
package main
import (
"encoding/json"
"fmt"
"io"
. "github.com/antonmedv/fx/pkg/json"
. "github.com/antonmedv/fx/pkg/reducer"
. "github.com/antonmedv/fx/pkg/theme"
2022-05-08 13:13:09 +00:00
"github.com/dop251/goja"
2022-04-29 21:17:39 +00:00
)
2022-05-08 13:13:09 +00:00
func stream(dec *json.Decoder, object interface{}, lang string, args []string, theme Theme, fxrc string) int {
var vm *goja.Runtime
var fn goja.Callable
2022-04-29 21:17:39 +00:00
var err error
2022-05-08 13:13:09 +00:00
if lang == "js" {
vm, fn, err = CreateJS(args, fxrc)
if err != nil {
fmt.Println(err)
return 1
}
}
2022-04-29 21:17:39 +00:00
for {
2022-05-08 13:13:09 +00:00
if object != nil {
if lang == "js" {
ReduceJS(vm, fn, object, theme)
} else {
Reduce(object, lang, args, theme, fxrc)
}
2022-04-29 21:17:39 +00:00
}
2022-05-08 13:13:09 +00:00
object, err = Parse(dec)
2022-04-29 21:17:39 +00:00
if err == io.EOF {
return 0
}
if err != nil {
fmt.Println("JSON Parse Error:", err.Error())
return 1
}
}
}