1 Star 0 Fork 24

夜丶丶/gout

forked from 小蚂蚁/gout 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
import.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
guonaihong 提交于 2020-01-10 23:35 +08:00 . dataflow-filter-export (#160)
package gout
import (
"bufio"
"bytes"
"github.com/guonaihong/gout/core"
"github.com/guonaihong/gout/dataflow"
"io"
"io/ioutil"
"net/http"
"strings"
)
type Import struct{}
func NewImport() *Import {
return &Import{}
}
const rawTextSpace = "\r\n "
func (i *Import) RawText(text interface{}) *Text {
var read io.Reader
r := &Text{}
out := dataflow.New()
// TODO 函数
r.SetGout(out)
switch body := text.(type) {
case string:
body = strings.TrimLeft(body, rawTextSpace)
read = strings.NewReader(body)
case []byte:
body = bytes.TrimLeft(body, rawTextSpace)
read = bytes.NewReader(body)
default:
r.Err = core.ErrUnknownType
return r
}
req, err := http.ReadRequest(bufio.NewReader(read))
if err != nil {
r.Err = err
return r
}
// TODO 探索下能否支持https
req.URL.Scheme = "http"
req.URL.Host = req.Host
req.RequestURI = ""
if req.GetBody == nil {
all, err := ioutil.ReadAll(req.Body)
if err != nil {
r.Err = err
return r
}
req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(all)), nil
}
req.Body = ioutil.NopCloser(bytes.NewReader(all))
}
r.SetRequest(req)
return r
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/nt_night/gout.git
git@gitee.com:nt_night/gout.git
nt_night
gout
gout
master

搜索帮助