-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
47 lines (38 loc) · 1.22 KB
/
Copy pathexample_test.go
File metadata and controls
47 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package bootstrap_test
import (
"fmt"
"net/http"
"github.com/aatuh/api-toolkit/contrib/v3/bootstrap"
"github.com/aatuh/api-toolkit/v3/endpoints/health"
)
type exampleSystemEndpointRouter struct {
patterns []string
}
func (r *exampleSystemEndpointRouter) Get(pattern string, _ http.HandlerFunc) {
r.patterns = append(r.patterns, pattern)
}
func ExampleMountSystemEndpointsToWithAdmin() {
router := &exampleSystemEndpointRouter{}
healthHandler := health.NewBasicHandler()
requireAdmin := func(next http.Handler) http.Handler { return next }
if err := configureSystemEndpoints(router, healthHandler, requireAdmin); err != nil {
panic(err)
}
fmt.Println(len(router.patterns) > 0)
// Output:
// true
}
func configureSystemEndpoints(router *exampleSystemEndpointRouter, healthHandler *health.Handler, requireAdmin func(http.Handler) http.Handler) error {
err := bootstrap.MountSystemEndpointsToWithAdmin(router, bootstrap.SystemEndpoints{
Health: healthHandler,
Metrics: bootstrap.PrometheusMetricsHandler(),
Pprof: http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}),
}, bootstrap.SystemEndpointAdminOptions{
RequireAdmin: requireAdmin,
EnablePprof: true,
})
if err != nil {
return err
}
return nil
}