MCPcopy Index your code
hub / github.com/getlantern/sysproxy / On

Function On

sysproxy.go:47–74  ·  view source on GitHub ↗

On tells OS to configure proxy through `addr` as host:port. It always returns a function that can be used to clear the system proxy setting. If the current process terminates before the clear function is called, the system proxy setting will be cleared anyway.

(addr string)

Source from the content-addressed store, hash-verified

45// process terminates before the clear function is called, the system proxy
46// setting will be cleared anyway.
47func On(addr string) (func() error, error) {
48 host, port, err := net.SplitHostPort(addr)
49 if err != nil {
50 return nil, fmt.Errorf("unable to parse address %v: %v", addr, err)
51 }
52 ip := net.ParseIP(host)
53 if ip != nil && ip.To4() == nil {
54 host = "[" + host + "]"
55 }
56
57 mu.Lock()
58 defer mu.Unlock()
59 if be == nil {
60 return nil, fmt.Errorf("call EnsureHelperToolPresent() first")
61 }
62
63 cmd := be.Command("on", host, port)
64 onErr := run(cmd)
65 off, offErr := waitAndCleanup(host, port)
66 if offErr != nil {
67 log.Errorf("Unable to prepare waitAndCleanup job: %v", offErr)
68 }
69 if onErr != nil {
70 return off, onErr
71 }
72 verifyErr := verify(addr)
73 return off, verifyErr
74}
75
76// Off immediately unsets the proxy at addr as the system proxy.
77func Off(addr string) error {

Callers 2

mainFunction · 0.92
TestGetOutputFunction · 0.85

Calls 3

runFunction · 0.85
waitAndCleanupFunction · 0.85
verifyFunction · 0.85

Tested by 1

TestGetOutputFunction · 0.68