mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-11-30 00:21:48 +00:00
27 lines
528 B
Go
27 lines
528 B
Go
package ipgeo
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func newGeoRequest(method, url string, timeout time.Duration) (*http.Request, context.CancelFunc, error) {
|
|
var (
|
|
ctx context.Context
|
|
cancel context.CancelFunc
|
|
)
|
|
if timeout > 0 {
|
|
ctx, cancel = context.WithTimeout(context.Background(), timeout)
|
|
} else {
|
|
ctx, cancel = context.WithCancel(context.Background())
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, method, url, nil)
|
|
if err != nil {
|
|
cancel()
|
|
return nil, nil, err
|
|
}
|
|
return req, cancel, nil
|
|
}
|