diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-22 14:23:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 14:23:42 +0200 |
commit | 86354a29a40fb97e334f951428239ab8e171e2dd (patch) | |
tree | 2f0d8cc2680aa4ccbaf865b427976b3f810b6920 /fetch.go | |
parent | ef9dc2464e10510bdcc4be9eae431e3dcf7f7999 (diff) |
Delete go implementation (#276)
The go prototype will remain at https://github.com/ry/deno/tree/golang
Diffstat (limited to 'fetch.go')
-rw-r--r-- | fetch.go | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/fetch.go b/fetch.go deleted file mode 100644 index 3b9cb5746..000000000 --- a/fetch.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2018 Ryan Dahl <ry@tinyclouds.org> -// All rights reserved. MIT License. -package deno - -import ( - "github.com/golang/protobuf/proto" - "io/ioutil" - "net/http" -) - -func InitFetch() { - Sub("fetch", func(buf []byte) []byte { - msg := &Msg{} - check(proto.Unmarshal(buf, msg)) - switch msg.Command { - case Msg_FETCH_REQ: - return Fetch( - msg.FetchReqId, - msg.FetchReqUrl) - default: - panic("[fetch] Unexpected message " + string(buf)) - } - }) -} - -func Fetch(id int32, targetUrl string) []byte { - logDebug("Fetch %d %s", id, targetUrl) - async(func() { - resMsg := &Msg{ - Command: Msg_FETCH_RES, - FetchResId: id, - } - - if !Perms.Net { - resMsg.Error = "Network access denied." - PubMsg("fetch", resMsg) - return - } - - resp, err := http.Get(targetUrl) - if err != nil { - resMsg.Error = err.Error() - PubMsg("fetch", resMsg) - return - } - if resp == nil { - resMsg.Error = "resp is nil " - PubMsg("fetch", resMsg) - return - } - - resMsg.FetchResStatus = int32(resp.StatusCode) - logDebug("fetch success %d %s", resMsg.FetchResStatus, targetUrl) - PubMsg("fetch", resMsg) - - // Now we read the body and send another message0 - - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if resp == nil { - resMsg.Error = "resp is nil " - PubMsg("fetch", resMsg) - return - } - - resMsg.FetchResBody = body - PubMsg("fetch", resMsg) - - // TODO streaming. - }) - return nil -} |