crowdsec/pkg/cwapi/pull.go
AlteredCoder d23512e9c6
improve logging (#164)
Co-authored-by: AlteredCoder <AlteredCoder>
2020-07-30 15:30:02 +02:00

25 lines
548 B
Go

package cwapi
import (
"fmt"
log "github.com/sirupsen/logrus"
)
func (ctx *ApiCtx) PullTop() ([]map[string]string, error) {
top := &PullResp{}
errResp := &ApiResp{}
resp, err := ctx.Http.New().Get(ctx.PullPath).Receive(top, errResp)
if err != nil {
return nil, fmt.Errorf("api pull: HTTP request creation failed: %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("api pull: return bad HTTP code (%d): %s", resp.StatusCode, errResp.Message)
}
log.Debugf("api pull: response : %+v", top.Body)
return top.Body, nil
}