mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
feat(iplist): make HTTP client part of Load API
This commit is contained in:
parent
9cbf82fc16
commit
a8cc57c4c9
@ -32,13 +32,9 @@ const (
|
||||
// that are themselves HTTP(S) URLs are recursively expanded up to
|
||||
// MaxNestedSources levels. URL responses are cached below cacheDir and the
|
||||
// cache remains available across process restarts.
|
||||
func Load(ctx context.Context, source, cacheDir string) ([]string, error) {
|
||||
return LoadWithClient(ctx, source, cacheDir, nil)
|
||||
}
|
||||
|
||||
// LoadWithClient is Load with an optional HTTP client. A nil client uses the
|
||||
// Load reads a source with an optional HTTP client. A nil client uses the
|
||||
// internal client with the package's standard timeout and transport policy.
|
||||
func LoadWithClient(ctx context.Context, source, cacheDir string, client *http.Client) ([]string, error) {
|
||||
func Load(ctx context.Context, source, cacheDir string, client *http.Client) ([]string, error) {
|
||||
if client == nil {
|
||||
client = https.NewInternalClient()
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func TestLoadWithClient(t *testing.T) {
|
||||
called = true
|
||||
return http.DefaultTransport.RoundTrip(r)
|
||||
})}
|
||||
entries, err := LoadWithClient(context.Background(), server.URL, t.TempDir(), client)
|
||||
entries, err := Load(context.Background(), server.URL, t.TempDir(), client)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -54,7 +54,7 @@ func TestLoadURLAuthCacheAndNested(t *testing.T) {
|
||||
defer outer.Close()
|
||||
|
||||
cacheDir := t.TempDir()
|
||||
got, err := Load(context.Background(), strings.Replace(outer.URL, "http://", "http://u:p@", 1), cacheDir)
|
||||
got, err := Load(context.Background(), strings.Replace(outer.URL, "http://", "http://u:p@", 1), cacheDir, nil)
|
||||
if err != nil || !authOK || len(got) != 1 || got[0] != "192.0.2.2" {
|
||||
t.Fatalf("auth=%v entries=%#v err=%v", authOK, got, err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user