lambda/examples/http_request_example/main.go

31 lines
645 B
Go
Raw Permalink Normal View History

2022-03-27 02:42:22 +00:00
package main
import (
"fmt"
"log"
"net/http"
"git.tuxpa.in/a/lambda"
"git.tuxpa.in/a/lambda/parallel"
"git.tuxpa.in/a/lambda/task"
)
type someResult struct {
Title string `json:"title"`
Id int `json:"id"`
}
func main() {
var requests = make([]*task.HttpRequest[someResult], 20)
for i := range requests {
r, _ := http.NewRequest("GET", fmt.Sprintf("https://jsonplaceholder.typicode.com/todos/%d", i+1), nil)
requests[i] = &task.HttpRequest[someResult]{
Req: *r,
}
}
results := lambda.Filter(parallel.Map(requests, requests[0].Json(), 4), requests[0].NoErr())
for _, v := range results {
log.Printf("%s", v)
}
}