• 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

73.91
/httpserver/handlergroup.go
1
package httpserver
2

3
import (
4
        "net/http"
5
)
6

7
// HandlerGroup represents a group of HTTP handlers that share common middlewares.
8
type HandlerGroup struct {
9
        mux         *http.ServeMux
10
        middlewares []Middleware
11
}
12

13
// NewHandlerGroup creates a new HandlerGroup with an initialized http.ServeMux.
14
func NewHandlerGroup() *HandlerGroup {
×
15
        return &HandlerGroup{mux: http.NewServeMux()}
×
16
}
×
17

18
// Use adds a middleware to the HandlerGroup's middleware chain.
19
func (hg *HandlerGroup) Use(middlewares ...Middleware) {
1✔
20
        hg.middlewares = append(hg.middlewares, middlewares...)
1✔
21
}
1✔
22

23
// UseFunc adds a function as a middleware to the HandlerGroup's middleware chain.
24
func (hg *HandlerGroup) UseFunc(middlewareFuncs ...func(http.Handler) http.Handler) {
1✔
25
        for _, middlewareFunc := range middlewareFuncs {
2✔
26
                hg.middlewares = append(hg.middlewares, MiddlewareFunc(middlewareFunc))
1✔
27
        }
1✔
28
}
29

30
// Handle registers an http.Handler for the given pattern, applying all
31
// middlewares in the HandlerGroup's chain.
32
func (hg *HandlerGroup) Handle(pattern string, handler http.Handler) {
1✔
33
        hg.mux.Handle(pattern, handler)
1✔
34
}
1✔
35

36
// HandleFunc registers an http.HandlerFunc for the given pattern, applying all
37
// middlewares in the HandlerGroup's chain.
38
func (hg *HandlerGroup) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) {
1✔
39
        hg.mux.Handle(pattern, http.HandlerFunc(handler))
1✔
40
}
1✔
41

NEW
42
func (hg *HandlerGroup) HandleGroup(pattern string, handler http.Handler) {
×
NEW
43
        hg.mux.Handle(pattern+"/", http.StripPrefix(pattern, handler))
×
NEW
44
}
×
45

46
// ServeHTTP implements the http.Handler interface, allowing HandlerGroup to
47
// be used as an HTTP handler itself.
48
func (hg *HandlerGroup) ServeHTTP(w http.ResponseWriter, r *http.Request) {
1✔
49
        wrappedMux := wrapHandlerInMiddleware(hg.mux, hg.middlewares)
1✔
50
        wrappedMux.ServeHTTP(w, r)
1✔
51
}
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