StartServer runs the imgproxy server. This function blocks until the context is cancelled. If hasStarted is not nil, it will be notified with the server address once the server is ready or about to be ready to accept requests.
(ctx context.Context, hasStarted chan net.Addr)
| 191 | // If hasStarted is not nil, it will be notified with the server address once |
| 192 | // the server is ready or about to be ready to accept requests. |
| 193 | func (i *Imgproxy) StartServer(ctx context.Context, hasStarted chan net.Addr) error { |
| 194 | go i.startMemoryTicker(ctx) |
| 195 | |
| 196 | ctx, cancel := context.WithCancel(ctx) |
| 197 | |
| 198 | if err := i.monitoring.StartPrometheus(cancel); err != nil { |
| 199 | return err |
| 200 | } |
| 201 | |
| 202 | router, err := i.BuildRouter() |
| 203 | if err != nil { |
| 204 | return err |
| 205 | } |
| 206 | |
| 207 | s, err := server.Start(cancel, router) |
| 208 | if err != nil { |
| 209 | return err |
| 210 | } |
| 211 | defer s.Shutdown(context.Background()) |
| 212 | |
| 213 | if hasStarted != nil { |
| 214 | hasStarted <- s.Addr |
| 215 | close(hasStarted) |
| 216 | } |
| 217 | |
| 218 | <-ctx.Done() |
| 219 | |
| 220 | return nil |
| 221 | } |
| 222 | |
| 223 | // Close gracefully shuts down the imgproxy instance |
| 224 | func (i *Imgproxy) Close(ctx context.Context) { |
no test coverage detected