Refactor database login into a separate module

This commit is contained in:
Daan Sprenkels
2019-12-03 23:08:58 +01:00
parent 8b87cd0f8a
commit 0cfad96b68
10 changed files with 489 additions and 430 deletions

View File

@@ -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")