summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/main.go b/main.go
index 3ee79fb6b..4612849db 100644
--- a/main.go
+++ b/main.go
@@ -3,12 +3,37 @@ package main
import (
"github.com/golang/protobuf/proto"
"github.com/ry/v8worker2"
+ "io/ioutil"
"os"
)
-func recv(msg []byte) []byte {
- println("recv cb", string(msg))
- return nil
+func ReadFileSync(filename string) []byte {
+ buf, err := ioutil.ReadFile(filename)
+ msg := &Msg{Kind: Msg_DATA_RESPONSE}
+ if err != nil {
+ msg.Error = err.Error()
+ } else {
+ msg.Data = buf
+ }
+ out, err := proto.Marshal(msg)
+ if err != nil {
+ panic(err)
+ }
+ return out
+}
+
+func recv(buf []byte) []byte {
+ msg := &Msg{}
+ err := proto.Unmarshal(buf, msg)
+ if err != nil {
+ panic(err)
+ }
+ switch msg.Kind {
+ case Msg_READ_FILE_SYNC:
+ return ReadFileSync(msg.Path)
+ default:
+ panic("Unexpected message")
+ }
}
func loadAsset(w *v8worker2.Worker, path string) {