MCPcopy
hub / github.com/fagongzi/manba / Start

Method Start

pkg/proxy/proxy.go:108–164  ·  view source on GitHub ↗

Start start proxy

()

Source from the content-addressed store, hash-verified

106
107// Start start proxy
108func (p *Proxy) Start() {
109 go p.listenToStop()
110
111 util.StartMetricsPush(p.runner, p.cfg.Metric)
112
113 p.readyToCopy()
114 p.readyToDispatch()
115
116 log.Infof("gateway proxy started at <%s>", p.cfg.Addr)
117
118 if !p.cfg.Option.EnableWebSocket {
119 err := fasthttp.ListenAndServe(p.cfg.Addr, p.ServeFastHTTP)
120 if err != nil {
121 log.Fatalf("gateway proxy start failed, errors:\n%+v",
122 err)
123 }
124 return
125 }
126
127 l, err := net.Listen("tcp", p.cfg.Addr)
128 if err != nil {
129 log.Fatalf("gateway proxy start failed, errors:\n%+v",
130 err)
131 }
132
133 m := cmux.New(l)
134 webSocketL := m.Match(cmux.HTTP1HeaderField("Upgrade", "websocket"))
135 httpL := m.Match(cmux.Any())
136
137 go func() {
138 httpS := fasthttp.Server{
139 Handler: p.ServeFastHTTP,
140 }
141 err = httpS.Serve(httpL)
142 if err != nil {
143 log.Fatalf("gateway proxy start failed, errors:\n%+v",
144 err)
145 }
146 }()
147
148 go func() {
149 webSocketS := &http.Server{
150 Handler: p,
151 }
152 err = webSocketS.Serve(webSocketL)
153 if err != nil {
154 log.Fatalf("gateway proxy start failed, errors:\n%+v",
155 err)
156 }
157 }()
158
159 err = m.Serve()
160 if err != nil {
161 log.Fatalf("gateway proxy start failed, errors:\n%+v",
162 err)
163 }
164}
165

Callers 3

mainFunction · 0.95
mainFunction · 0.80
mainFunction · 0.80

Calls 4

listenToStopMethod · 0.95
readyToCopyMethod · 0.95
readyToDispatchMethod · 0.95
StartMetricsPushFunction · 0.92

Tested by

no test coverage detected