//
// call Close() after writer fin
func WithCtxCopy(ctx context.Context, callTree string, to time.Duration, w []io.Writer, r io.Reader, panicf ...func(s string)) error {
- rwc := WithCtxTO(ctx, callTree, to, w, r)
+ rwc := WithCtxTO(ctx, callTree, to, w, r, panicf...)
defer rwc.Close()
for buf := make([]byte, 2048); true; {
if n, e := rwc.Read(buf); n != 0 {
)
type Rval struct {
- Url string
- PostStr string
- Timeout int
- Proxy string
- Retry int
- SleepTime int
+ Url string
+ PostStr string
+ Proxy string
+ Retry int
+ // Millisecond
+ Timeout int
+ // Millisecond
+ SleepTime int
+ // Millisecond
WriteLoopTO int
JustResponseCode bool
NoResponse bool
writeLoopTO := val.WriteLoopTO
if writeLoopTO == 0 {
- writeLoopTO = 1000
+ if val.Timeout > 0 {
+ writeLoopTO = val.Timeout + 500
+ } else {
+ writeLoopTO = 1000
+ }
}
// io copy
- err = errors.Join(err, pio.WithCtxCopy(req.Context(), t.callTree, time.Duration(int(time.Millisecond)*writeLoopTO), ws, resReadCloser))
+ var panicf = func(s string) {
+ err = errors.Join(err, errors.New(s))
+ }
+ err = errors.Join(err, pio.WithCtxCopy(req.Context(), t.callTree, time.Duration(int(time.Millisecond)*writeLoopTO), ws, resReadCloser, panicf))
resp.Body.Close()