Slide 23
Slide 23 text
DPOUFYUͷొ
(P͔ΒDPOUFYUϥΠϒϥϦ͕ొ
λΠϜΞτॲཧͳͲͷѻ͍͕ΑΓ໌շʹ
url := flag.String("u", "https://www.desamis.co.jp/", "URL"
)
timeout := flag.Duration("t", 500 * time.Millisecond, "ଓλΠϜΞτ"
)
flag.Parse(
)
ctx, _ := context.WithTimeout(context.Background(), *timeout
)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil
)
if err != nil
{
panic(err
)
}
resp, err := new(http.Client).Do(req) // ࢦఆͨ͠λΠϜΞτظؒΛ͑Δͱࣦഊ͢Δ
σϑΥϧτಈ࡞ʹͤΔͱ͖ context.Background() Λ͏
ઃܭ్தͩͬͨΓͰఆ·Βͳ͍࣌༻ʹ context.TODO() ͋Δ
👇