Support none database type to disable stats/telemetry

Fixes #21
This commit is contained in:
Maddie Zhan
2021-09-18 01:48:10 +08:00
parent 7204ae2e19
commit 8c1aa6b39b
7 changed files with 55 additions and 5 deletions

View File

@ -5,12 +5,10 @@ import (
"errors"
"time"
"go.etcd.io/bbolt"
"github.com/librespeed/speedtest/database/schema"
_ "github.com/go-sql-driver/mysql"
log "github.com/sirupsen/logrus"
"go.etcd.io/bbolt"
)
const (

View File

@ -4,8 +4,11 @@ import (
"github.com/librespeed/speedtest/config"
"github.com/librespeed/speedtest/database/bolt"
"github.com/librespeed/speedtest/database/mysql"
"github.com/librespeed/speedtest/database/none"
"github.com/librespeed/speedtest/database/postgresql"
"github.com/librespeed/speedtest/database/schema"
log "github.com/sirupsen/logrus"
)
var (
@ -26,5 +29,9 @@ func SetDBInfo(conf *config.Config) {
DB = mysql.Open(conf.DatabaseHostname, conf.DatabaseUsername, conf.DatabasePassword, conf.DatabaseName)
case "bolt":
DB = bolt.Open(conf.DatabaseFile)
case "none":
DB = none.Open("")
default:
log.Fatalf("Unsupported database type: %s", conf.DatabaseType)
}
}

23
database/none/none.go Normal file
View File

@ -0,0 +1,23 @@
package none
import (
"github.com/librespeed/speedtest/database/schema"
)
type None struct{}
func Open(_ string) *None {
return &None{}
}
func (n *None) Insert(_ *schema.TelemetryData) error {
return nil
}
func (n *None) FetchByUUID(_ string) (*schema.TelemetryData, error) {
return &schema.TelemetryData{}, nil
}
func (n *None) FetchLast100() ([]schema.TelemetryData, error) {
return []schema.TelemetryData{}, nil
}