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

mishankov / platforma / 18907069962

29 Oct 2025 11:58AM UTC coverage: 20.604% (+0.05%) from 20.552%
18907069962

Pull #14

github

mishankov
Disable linter for demo-app directory
Pull Request #14: Httpserver cleanup

3 of 8 new or added lines in 3 files covered. (37.5%)

5 existing lines in 1 file now uncovered.

232 of 1126 relevant lines covered (20.6%)

0.24 hits per line

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

22.22
/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
        mux             *http.ServeMux
18
        port            string
19
        shutdownTimeout time.Duration
20
        middlewares     []Middleware
21
}
22

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

27
func (s *HttpServer) Handle(pattern string, handler http.Handler) {
1✔
28
        s.mux.Handle(pattern, handler)
1✔
29
}
1✔
30

31
func (s *HttpServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) {
1✔
32
        s.mux.HandleFunc(pattern, http.HandlerFunc(handler))
1✔
33
}
1✔
34

35
func (s *HttpServer) HandleGroup(pattern string, handler http.Handler) {
×
36
        s.mux.Handle(pattern+"/", http.StripPrefix(pattern, handler))
×
37
}
×
38

39
func (s *HttpServer) Use(middlewares ...Middleware) {
×
40
        s.middlewares = append(s.middlewares, middlewares...)
×
41
}
×
42

43
func (s *HttpServer) UseFunc(middlewareFuncs ...func(http.Handler) http.Handler) {
×
44
        for _, middlewareFunc := range middlewareFuncs {
×
45
                s.middlewares = append(s.middlewares, MiddlewareFunc(middlewareFunc))
×
46
        }
×
47
}
48

49
func (s *HttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
1✔
50
        s.mux.ServeHTTP(w, r)
1✔
51
}
1✔
52

53
func (s *HttpServer) Run(ctx context.Context) error {
×
54
        server := &http.Server{
×
55
                Addr:              ":" + s.port,
×
56
                Handler:           wrapHandlerInMiddleware(s.mux, s.middlewares),
×
57
                ReadHeaderTimeout: 1 * time.Second,
×
58
        }
×
59

×
60
        go func() {
×
61
                log.InfoContext(ctx, "starting http server", "address", server.Addr)
×
62

×
63
                if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
×
64
                        log.ErrorContext(ctx, "HTTP server error", "error", err)
×
65
                }
×
66
                log.InfoContext(ctx, "stopped serving new connections.")
×
67
        }()
68

69
        sigChan := make(chan os.Signal, 1)
×
70
        signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
×
71
        <-sigChan
×
72

×
73
        shutdownCtx, shutdownRelease := context.WithTimeout(ctx, s.shutdownTimeout)
×
74
        defer shutdownRelease()
×
75

×
76
        if err := server.Shutdown(shutdownCtx); err != nil {
×
NEW
77
                return fmt.Errorf("failed to gracefully shutdown HTTP server: %w", err)
×
78
        }
×
79
        log.InfoContext(ctx, "graceful shutdown completed.")
×
80

×
81
        return nil
×
82
}
83

UNCOV
84
func (s *HttpServer) Healthcheck(ctx context.Context) any {
×
UNCOV
85
        return map[string]any{
×
UNCOV
86
                "port": s.port,
×
UNCOV
87
        }
×
UNCOV
88
}
×
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