debugapi.go 724 Bytes
Newer Older
1 2 3 4
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

5 6 7 8
package debugapi

import (
	"net/http"
Janos Guljas's avatar
Janos Guljas committed
9

10
	"github.com/ethersphere/bee/pkg/logging"
11
	"github.com/ethersphere/bee/pkg/p2p"
Janos Guljas's avatar
Janos Guljas committed
12
	"github.com/prometheus/client_golang/prometheus"
13 14
)

Janos Guljas's avatar
Janos Guljas committed
15 16 17 18 19
type Service interface {
	http.Handler
	MustRegisterMetrics(cs ...prometheus.Collector)
}

20 21 22
type server struct {
	Options
	http.Handler
Janos Guljas's avatar
Janos Guljas committed
23 24

	metricsRegistry *prometheus.Registry
25 26
}

27
type Options struct {
28
	P2P    p2p.Service
29
	Logger logging.Logger
30
}
31

Janos Guljas's avatar
Janos Guljas committed
32
func New(o Options) Service {
33
	s := &server{
Janos Guljas's avatar
Janos Guljas committed
34 35
		Options:         o,
		metricsRegistry: newMetricsRegistry(),
36 37 38 39 40 41
	}

	s.setupRouting()

	return s
}