Refactor database login into a separate module
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gitea.hashru.nl/dsprenkels/rushlink/internal/db"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -13,7 +15,7 @@ import (
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
func StartMetricsServer(addr string) {
|
||||
func StartMetricsServer(addr string, db *db.Database) {
|
||||
var (
|
||||
_ = promauto.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: "rushlink",
|
||||
@@ -22,7 +24,7 @@ func StartMetricsServer(addr string) {
|
||||
Help: "The current amount of pastes in the database.",
|
||||
}, func() float64 {
|
||||
var metric float64
|
||||
if err := DB.View(func(tx *bolt.Tx) error {
|
||||
if err := db.Bolt.View(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket([]byte("pastes"))
|
||||
if bucket == nil {
|
||||
return errors.New("bucket 'pastes' could not be found")
|
||||
|
||||
Reference in New Issue
Block a user