MCPcopy Index your code
hub / github.com/codegangsta/gin / Run

Method Run

lib/proxy.go:29–63  ·  view source on GitHub ↗
(config *Config)

Source from the content-addressed store, hash-verified

27}
28
29func (p *Proxy) Run(config *Config) error {
30
31 // create our reverse proxy
32 url, err := url.Parse(config.ProxyTo)
33 if err != nil {
34 return err
35 }
36 p.proxy = httputil.NewSingleHostReverseProxy(url)
37 p.to = url
38
39 server := http.Server{Handler: http.HandlerFunc(p.defaultHandler)}
40
41 if config.CertFile != "" && config.KeyFile != "" {
42 cer, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile)
43 if err != nil {
44 return err
45 }
46
47 server.TLSConfig = &tls.Config{Certificates: []tls.Certificate{cer}}
48
49 p.listener, err = tls.Listen("tcp", fmt.Sprintf("%s:%d", config.Laddr, config.Port), server.TLSConfig)
50 if err != nil {
51 return err
52 }
53 } else {
54 p.listener, err = net.Listen("tcp", fmt.Sprintf("%s:%d", config.Laddr, config.Port))
55 if err != nil {
56 return err
57 }
58 }
59
60 go server.Serve(p.listener)
61
62 return nil
63}
64
65func (p *Proxy) Close() error {
66 return p.listener.Close()

Callers 5

MainActionFunction · 0.95
Test_Proxy_RunFunction · 0.95
Test_ProxyingFunction · 0.95
Test_Proxying_WebsocketFunction · 0.95

Calls

no outgoing calls

Tested by 4

Test_Proxy_RunFunction · 0.76
Test_ProxyingFunction · 0.76
Test_Proxying_WebsocketFunction · 0.76