Init commit, base struct and redis connection
This commit is contained in:
28
handlers/worker.go
Normal file
28
handlers/worker.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"uebucch/structs"
|
||||
)
|
||||
func worker(id int, jobs <-chan structs.WebhookJob) {
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
|
||||
for job := range jobs {
|
||||
req, _ := http.NewRequest(job.Method, job.TargetURL, bytes.NewBuffer(job.Payload))
|
||||
for k, v := range job.Headers {
|
||||
req.Header[k] = v
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Printf("Worker %d: Errore nell'inoltro: %v", id, err)
|
||||
continue
|
||||
}
|
||||
resp.Body.Close()
|
||||
log.Printf("Worker %d: Inoltrato con successo a %s", id, job.TargetURL)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user