stream

package
v1.0.7-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EncodeHttpRequestIsNilErr = errors.New("you cannot encode http request an nil type")
)

http

View Source
var (
	InvalidEncodingErr = errors.New("decode invalid content, please check your content")
)

shortStream

Functions

func EncodeHttpRequest

func EncodeHttpRequest(req *HttpRequest) ([]byte, error)

func EncodeShortStream

func EncodeShortStream(s Stream) []byte

这个方法编码最低级的 stream

Types

type CallbackFunc

type CallbackFunc func(response *HttpResponse) (Stream, error)

func (CallbackFunc) Name

func (c CallbackFunc) Name() string

func name

type HttpRequest

type HttpRequest struct {
	*http.Request

	// 爬虫回调函数
	Callback CallbackFunc
	// 跳过过滤器
	SkipFilter bool
	// 带上请求的一些参数
	Meta map[string]interface{}
	// 下载失败重新尝试次数
	Retry int
	// contains filtered or unexported fields
}

func BodyRequest

func BodyRequest(
	self Stream,
	method string,
	url string,
	body io.Reader,
	callback CallbackFunc,
) (*HttpRequest, error)

func DecodeHttpRequest

func DecodeHttpRequest(b []byte) (*HttpRequest, error)

func FormRequest

func FormRequest(
	self Stream,
	url string,
	fromData map[string][]string,
	callback CallbackFunc,
) (*HttpRequest, error)

func JsonRequest

func JsonRequest(
	self Stream,
	url string,
	jsonData map[string]interface{},
	callback CallbackFunc,
) (*HttpRequest, error)

func Request

func Request(self Stream, url string, callback CallbackFunc) (*HttpRequest, error)

几种 http new func

func (*HttpRequest) FQDN

func (h *HttpRequest) FQDN() string

func (*HttpRequest) UId

func (h *HttpRequest) UId() string

type HttpResponse

type HttpResponse struct {
	*http.Response
	// 带上请求的一些参数
	Meta map[string]interface{}

	Stream

	// 解析函数
	Callback CallbackFunc
	// contains filtered or unexported fields
}

func (*HttpResponse) Bytes

func (h *HttpResponse) Bytes() []byte

func (*HttpResponse) ParseName

func (h *HttpResponse) ParseName() string

func (*HttpResponse) Text

func (h *HttpResponse) Text() string

func (*HttpResponse) WithHttpAndRequestStream

func (h *HttpResponse) WithHttpAndRequestStream(sReq *HttpRequest, req *http.Response)

func (*HttpResponse) Xpath

func (h *HttpResponse) Xpath(expr string) []*xpath

type Item

type Item interface {
	Stream
	Filed()
	IName() string
}

func BasicItem

func BasicItem(self Stream) Item

func BasicItemBandName

func BasicItemBandName(self Stream, s string) Item

type Stream

type Stream interface {
	UId() string
	FQDN() string
}

控制流

func DecodeShortStream

func DecodeShortStream(buf []byte) (Stream, error)

func StreamListRangeFloat

func StreamListRangeFloat(self Stream, only func(value float64) (Stream, error), f []float64) (Stream, error)

func StreamListRangeInt

func StreamListRangeInt(self Stream, only func(i int) (Stream, error), start, end int) (Stream, error)

func StreamListRangeString

func StreamListRangeString(self Stream, only func(value string) (Stream, error), s []string) (Stream, error)

func StreamLists

func StreamLists(self Stream, streams ...Stream) Stream

type StreamList

type StreamList struct {
	Stream
	// contains filtered or unexported fields
}

func (*StreamList) Iterator

func (s *StreamList) Iterator() func() Stream

迭代器模式

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL