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

mishankov / platforma / 18909092331

29 Oct 2025 01:13PM UTC coverage: 22.883% (+2.3%) from 20.552%
18909092331

Pull #14

github

mishankov
Refactor HttpServer to use embedded HandlerGroup
Pull Request #14: Httpserver cleanup

1 of 9 new or added lines in 4 files covered. (11.11%)

4 existing lines in 1 file now uncovered.

254 of 1110 relevant lines covered (22.88%)

0.26 hits per line

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

22.86
/httpserver/httpserver.go
1
package httpserver
2

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

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

16
type HttpServer struct {
17
        HandlerGroup
18
        port            string
19
        shutdownTimeout time.Duration
20
}
21

22
func New(port string, shutdownTimeout time.Duration) *HttpServer {
1✔
23
        return &HttpServer{HandlerGroup: HandlerGroup{mux: http.NewServeMux()}, port: port, shutdownTimeout: shutdownTimeout}
1✔
24
}
1✔
25

UNCOV
26
func (s *HttpServer) Run(ctx context.Context) error {
×
UNCOV
27
        server := &http.Server{
×
28
                Addr:              ":" + s.port,
×
29
                Handler:           wrapHandlerInMiddleware(s.mux, s.middlewares),
×
30
                ReadHeaderTimeout: 1 * time.Second,
×
31
        }
×
32

×
33
        go func() {
×
34
                log.InfoContext(ctx, "starting http server", "address", server.Addr)
×
35

×
36
                if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
×
37
                        log.ErrorContext(ctx, "HTTP server error", "error", err)
×
38
                }
×
39
                log.InfoContext(ctx, "stopped serving new connections.")
×
40
        }()
41

UNCOV
42
        sigChan := make(chan os.Signal, 1)
×
UNCOV
43
        signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
×
44
        <-sigChan
×
45

×
46
        shutdownCtx, shutdownRelease := context.WithTimeout(ctx, s.shutdownTimeout)
×
47
        defer shutdownRelease()
×
48

×
49
        if err := server.Shutdown(shutdownCtx); err != nil {
×
NEW
50
                return fmt.Errorf("failed to gracefully shutdown HTTP server: %w", err)
×
51
        }
×
52
        log.InfoContext(ctx, "graceful shutdown completed.")
×
53

×
54
        return nil
×
55
}
56

57
func (s *HttpServer) Healthcheck(ctx context.Context) any {
1✔
58
        return map[string]any{
1✔
59
                "port": s.port,
1✔
60
        }
1✔
61
}
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