-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_res.go
52 lines (40 loc) · 1.41 KB
/
call_res.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package withttp
import "github.com/sonirico/withttp/csvparser"
func (c *Call[T]) Response(opts ...ResOption) *Call[T] {
c.resOptions = append(c.resOptions, opts...)
return c
}
func (c *Call[T]) WithReadBody() *Call[T] {
return c.withRes(WithParseBodyRaw[T]())
}
func (c *Call[T]) WithParseStreamChan(factory StreamFactory[T], ch chan<- T) *Call[T] {
return c.withRes(WithParseStreamChan[T](factory, ch))
}
func (c *Call[T]) WithParseStream(factory StreamFactory[T], fn func(T) bool) *Call[T] {
return c.withRes(WithParseStream[T](factory, fn))
}
func (c *Call[T]) WithParseJSONEachRowChan(out chan<- T) *Call[T] {
return c.WithParseStreamChan(NewJSONEachRowStreamFactory[T](), out)
}
func (c *Call[T]) WithParseJSONEachRow(fn func(T) bool) *Call[T] {
return c.WithParseStream(NewJSONEachRowStreamFactory[T](), fn)
}
func (c *Call[T]) WithParseCSV(
ignoreLines int,
parser csvparser.Parser[T],
fn func(T) bool,
) *Call[T] {
return c.WithParseStream(NewCSVStreamFactory[T](ignoreLines, parser), fn)
}
func (c *Call[T]) WithIgnoreResponseBody() *Call[T] {
return c.withRes(WithIgnoredBody[T]())
}
func (c *Call[T]) WithParseJSON() *Call[T] {
return c.withRes(WithParseJSON[T]())
}
func (c *Call[T]) WithAssert(fn func(req Response) error) *Call[T] {
return c.withRes(WithAssertion[T](fn))
}
func (c *Call[T]) WithExpectedStatusCodes(states ...int) *Call[T] {
return c.withRes(WithExpectedStatusCodes[T](states...))
}