MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / GetCachedDialer

Function GetCachedDialer

dialer/cache.go:28–62  ·  view source on GitHub ↗
(u *url.URL, next xproxy.Dialer)

Source from the content-addressed store, hash-verified

26})
27
28func GetCachedDialer(u *url.URL, next xproxy.Dialer) (xproxy.Dialer, error) {
29 params, err := url.ParseQuery(u.RawQuery)
30 if err != nil {
31 return nil, err
32 }
33 if !params.Has("url") {
34 return nil, errors.New("cached dialer: no \"url\" parameter specified")
35 }
36 parsedURL, err := url.Parse(params.Get("url"))
37 if err != nil {
38 return nil, fmt.Errorf("unable to parse proxy URL: %w", err)
39 }
40 if !params.Has("ttl") {
41 return nil, errors.New("cached dialer: no \"ttl\" parameter specified")
42 }
43 ttl, err := time.ParseDuration(params.Get("ttl"))
44 if err != nil {
45 return nil, fmt.Errorf("cached dialer: unable to parse TTL duration %q: %w", params.Get("ttl"), err)
46 }
47 item := dialerCache.GetOrCreate(
48 dialerCacheKey{
49 url: params.Get("url"),
50 next: next,
51 },
52 func() *dialerCacheValue {
53 dialer, err := xproxy.FromURL(parsedURL, next)
54 return &dialerCacheValue{
55 expires: time.Now().Add(ttl),
56 dialer: dialer,
57 err: err,
58 }
59 },
60 )
61 return item.dialer, item.err
62}

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.80
HasMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected