wip: output, pipe

This commit is contained in:
loveuer
2024-04-01 18:13:10 +08:00
parent 195fbcd308
commit 4c40041b3d
16 changed files with 445 additions and 59 deletions

View File

@ -20,3 +20,19 @@ func Timeout(seconds ...int) (ctx context.Context) {
return
}
func TimeoutCtx(parent context.Context, seconds ...int) (ctx context.Context) {
var (
duration time.Duration
)
if len(seconds) > 0 && seconds[0] > 0 {
duration = time.Duration(seconds[0]) * time.Second
} else {
duration = time.Duration(30) * time.Second
}
ctx, _ = context.WithTimeout(parent, duration)
return
}

14
internal/util/es7.go Normal file
View File

@ -0,0 +1,14 @@
package util
import (
"fmt"
"github.com/elastic/go-elasticsearch/v7/esapi"
)
func CheckES7Response(result *esapi.Response) error {
if result.StatusCode != 200 {
return fmt.Errorf("status=%s msg=%s", result.StatusCode, result.String())
}
return nil
}