• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mishankov / platforma / 18916201405

29 Oct 2025 05:08PM UTC coverage: 25.045% (+4.5%) from 20.552%
18916201405

Pull #14

github

mishankov
Add revive checks to httpserver
Pull Request #14: Httpserver cleanup

12 of 15 new or added lines in 4 files covered. (80.0%)

278 of 1110 relevant lines covered (25.05%)

0.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

22.86
/httpserver/httpserver.go
1
// Package httpserver provides HTTP server functionality with middleware support.
2
package httpserver
3

4
import (
5
        "context"
6
        "errors"
7
        "fmt"
8
        "net/http"
9
        "os"
10
        "os/signal"
11
        "syscall"
12
        "time"
13

14
        "github.com/mishankov/platforma/log"
15
)
16

17
type handleGroup = HandlerGroup
18

19
// HTTPServer represents an HTTP server with middleware support and graceful shutdown.
20
type HTTPServer struct {
21
        *handleGroup
22
        port            string
23
        shutdownTimeout time.Duration
24
}
25

26
// New creates a new HTTPServer instance with the specified port and shutdown timeout.
27
func New(port string, shutdownTimeout time.Duration) *HTTPServer {
1✔
28
        return &HTTPServer{handleGroup: NewHandlerGroup(), port: port, shutdownTimeout: shutdownTimeout}
1✔
29
}
1✔
30

31
// Run starts the HTTP server and handles graceful shutdown on interrupt signals.
NEW
32
func (s *HTTPServer) Run(ctx context.Context) error {
×
33
        server := &http.Server{
×
34
                Addr:              ":" + s.port,
×
35
                Handler:           wrapHandlerInMiddleware(s.mux, s.middlewares),
×
36
                ReadHeaderTimeout: 1 * time.Second,
×
37
        }
×
38

×
39
        go func() {
×
40
                log.InfoContext(ctx, "starting http server", "address", server.Addr)
×
41

×
42
                if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
×
43
                        log.ErrorContext(ctx, "HTTP server error", "error", err)
×
44
                }
×
45
                log.InfoContext(ctx, "stopped serving new connections.")
×
46
        }()
47

48
        sigChan := make(chan os.Signal, 1)
×
49
        signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
×
50
        <-sigChan
×
51

×
52
        shutdownCtx, shutdownRelease := context.WithTimeout(ctx, s.shutdownTimeout)
×
53
        defer shutdownRelease()
×
54

×
55
        if err := server.Shutdown(shutdownCtx); err != nil {
×
NEW
56
                return fmt.Errorf("failed to gracefully shutdown HTTP server: %w", err)
×
57
        }
×
58
        log.InfoContext(ctx, "graceful shutdown completed.")
×
59

×
60
        return nil
×
61
}
62

63
// Healthcheck returns health check information for the HTTP server.
64
func (s *HTTPServer) Healthcheck(_ context.Context) any {
1✔
65
        return map[string]any{
1✔
66
                "port": s.port,
1✔
67
        }
1✔
68
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc