MCPcopy Create free account
hub / github.com/NVIDIA/nvcf / Start

Method Start

src/libraries/go/lib/pkg/core/httpservice.go:134–178  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

132 return net.Listen("tcp", s.Addr)
133}
134
135func (s *HTTPService) Start(ctx context.Context) (net.Listener, error) {
136 log := GetLogger(ctx)
137
138 server := &http.Server{
139 Handler: s.Router,
140 ReadTimeout: s.ReadTimeout,
141 WriteTimeout: s.WriteTimeout,
142 IdleTimeout: s.IdleTimeout,
143 }
144 listener, err := s.initListener(ctx)
145 if err != nil {
146 return nil, err
147 }
148
149 go func() {
150 if s.TLSCertFile != "" || s.TLSKeyFile != "" {
151 log.Infof("Serving HTTPS at: %v", listener.Addr())
152 if err := server.ServeTLS(listener, s.TLSCertFile, s.TLSKeyFile); err != nil {
153 log.Error(err)
154 }
155 } else {
156 log.Infof("Serving HTTP at: %v", listener.Addr())
157 if err := server.Serve(listener); err != nil {
158 log.Error(err)
159 }
160 }
161 }()
162
163 go func() {
164 <-ctx.Done()
165
166 newCtx, cancel := context.WithTimeout(context.Background(), s.ShutDownGracePeriod)
167 defer cancel()
168
169 log.Infof("Shutting down HTTPService at %v", listener.Addr())
170 err = server.Shutdown(newCtx)
171 if err != nil {
172 log.Infof("failed to terminate HTTPService at %v, err: %v", listener.Addr(), err)
173 return
174 }
175 log.Infof("Terminated HTTPService at %v", listener.Addr())
176 }()
177
178 return listener, nil
179}
180
181const httpHealthRoutePath = "/healthz"

Callers 3

TestHTTPServiceStartFunction · 0.95
StartMethod · 0.95
StartMethod · 0.95

Calls 8

initListenerMethod · 0.95
GetLoggerFunction · 0.85
AddrMethod · 0.80
ServeMethod · 0.80
DoneMethod · 0.80
WithTimeoutMethod · 0.80
ErrorMethod · 0.65
ShutdownMethod · 0.65

Tested by 1

TestHTTPServiceStartFunction · 0.76