| 26 | return s |
| 27 | } |
| 28 | func (s Server) Run(ctx context.Context) error { |
| 29 | go func() { |
| 30 | <-ctx.Done() |
| 31 | slog.Warn("context cancelled, shutting down") |
| 32 | ctxTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 33 | err := s.httpServer.Shutdown(ctxTimeout) |
| 34 | cancel() |
| 35 | if err != nil { |
| 36 | slog.Error("httpServer.Shutdown() error", "error", err) |
| 37 | } |
| 38 | }() |
| 39 | |
| 40 | err := s.httpServer.ListenAndServe() |
| 41 | if err != nil && !errors.Is(err, http.ErrServerClosed) { |
| 42 | return fmt.Errorf("httpServer.ListenAndServe() error: %w", err) |
| 43 | } |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | type SObject struct { |
| 48 | Time time.Time `json:"time"` |