mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
Added support for sqlite as database backend
This commit is contained in:
parent
619201ec9b
commit
216c6d85b2
19
app.go
19
app.go
@ -22,6 +22,8 @@ type Config struct {
|
|||||||
PrivateKeyPath string
|
PrivateKeyPath string
|
||||||
DerpMap *tailcfg.DERPMap
|
DerpMap *tailcfg.DERPMap
|
||||||
|
|
||||||
|
DBtype string
|
||||||
|
DBpath string
|
||||||
DBhost string
|
DBhost string
|
||||||
DBport int
|
DBport int
|
||||||
DBname string
|
DBname string
|
||||||
@ -60,11 +62,22 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pubKey := privKey.Public()
|
pubKey := privKey.Public()
|
||||||
|
|
||||||
|
var dbString string
|
||||||
|
switch cfg.DBtype {
|
||||||
|
case "postgres":
|
||||||
|
dbString = fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s sslmode=disable", cfg.DBhost,
|
||||||
|
cfg.DBport, cfg.DBname, cfg.DBuser, cfg.DBpass)
|
||||||
|
case "sqlite3":
|
||||||
|
dbString = cfg.DBpath
|
||||||
|
default:
|
||||||
|
return nil, errors.New("Unsupported DB")
|
||||||
|
}
|
||||||
|
|
||||||
h := Headscale{
|
h := Headscale{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
dbType: "postgres",
|
dbType: cfg.DBtype,
|
||||||
dbString: fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s sslmode=disable", cfg.DBhost,
|
dbString: dbString,
|
||||||
cfg.DBport, cfg.DBname, cfg.DBuser, cfg.DBpass),
|
|
||||||
privateKey: privKey,
|
privateKey: privKey,
|
||||||
publicKey: &pubKey,
|
publicKey: &pubKey,
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ func getHeadscaleApp() (*headscale.Headscale, error) {
|
|||||||
PrivateKeyPath: absPath(viper.GetString("private_key_path")),
|
PrivateKeyPath: absPath(viper.GetString("private_key_path")),
|
||||||
DerpMap: derpMap,
|
DerpMap: derpMap,
|
||||||
|
|
||||||
|
DBtype: viper.GetString("db_type"),
|
||||||
|
DBpath: viper.GetString("db_path"),
|
||||||
DBhost: viper.GetString("db_host"),
|
DBhost: viper.GetString("db_host"),
|
||||||
DBport: viper.GetInt("db_port"),
|
DBport: viper.GetInt("db_port"),
|
||||||
DBname: viper.GetString("db_name"),
|
DBname: viper.GetString("db_name"),
|
||||||
|
1
db.go
1
db.go
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres" // sql driver
|
_ "github.com/jinzhu/gorm/dialects/postgres" // sql driver
|
||||||
|
_ "github.com/jinzhu/gorm/dialects/sqlite" // sql driver
|
||||||
)
|
)
|
||||||
|
|
||||||
const dbVersion = "1"
|
const dbVersion = "1"
|
||||||
|
Loading…
Reference in New Issue
Block a user