mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-29 18:33:05 +00:00
Add and fix goconst
This commit is contained in:
parent
c9c16c7fb8
commit
9390348a65
3 changed files with 7 additions and 6 deletions
|
@ -39,7 +39,6 @@ linters:
|
||||||
- gocritic
|
- gocritic
|
||||||
- forbidigo
|
- forbidigo
|
||||||
- dupl
|
- dupl
|
||||||
- goconst
|
|
||||||
- varnamelen
|
- varnamelen
|
||||||
- makezero
|
- makezero
|
||||||
- paralleltest
|
- paralleltest
|
||||||
|
|
6
app.go
6
app.go
|
@ -48,6 +48,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AUTH_PREFIX = "Bearer "
|
AUTH_PREFIX = "Bearer "
|
||||||
|
POSTGRESQL = "postgresql"
|
||||||
|
SQLITE = "sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config contains the initial Headscale configuration.
|
// Config contains the initial Headscale configuration.
|
||||||
|
@ -150,7 +152,7 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
|
||||||
|
|
||||||
var dbString string
|
var dbString string
|
||||||
switch cfg.DBtype {
|
switch cfg.DBtype {
|
||||||
case "postgres":
|
case POSTGRESQL:
|
||||||
dbString = fmt.Sprintf(
|
dbString = fmt.Sprintf(
|
||||||
"host=%s port=%d dbname=%s user=%s password=%s sslmode=disable",
|
"host=%s port=%d dbname=%s user=%s password=%s sslmode=disable",
|
||||||
cfg.DBhost,
|
cfg.DBhost,
|
||||||
|
@ -159,7 +161,7 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
|
||||||
cfg.DBuser,
|
cfg.DBuser,
|
||||||
cfg.DBpass,
|
cfg.DBpass,
|
||||||
)
|
)
|
||||||
case "sqlite3":
|
case SQLITE:
|
||||||
dbString = cfg.DBpath
|
dbString = cfg.DBpath
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported DB")
|
return nil, errors.New("unsupported DB")
|
||||||
|
|
6
db.go
6
db.go
|
@ -24,7 +24,7 @@ func (h *Headscale) initDB() error {
|
||||||
}
|
}
|
||||||
h.db = db
|
h.db = db
|
||||||
|
|
||||||
if h.dbType == "postgres" {
|
if h.dbType == POSTGRESQL {
|
||||||
db.Exec("create extension if not exists \"uuid-ossp\";")
|
db.Exec("create extension if not exists \"uuid-ossp\";")
|
||||||
}
|
}
|
||||||
err = db.AutoMigrate(&Machine{})
|
err = db.AutoMigrate(&Machine{})
|
||||||
|
@ -66,12 +66,12 @@ func (h *Headscale) openDB() (*gorm.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch h.dbType {
|
switch h.dbType {
|
||||||
case "sqlite3":
|
case SQLITE:
|
||||||
db, err = gorm.Open(sqlite.Open(h.dbString), &gorm.Config{
|
db, err = gorm.Open(sqlite.Open(h.dbString), &gorm.Config{
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
Logger: log,
|
Logger: log,
|
||||||
})
|
})
|
||||||
case "postgres":
|
case POSTGRESQL:
|
||||||
db, err = gorm.Open(postgres.Open(h.dbString), &gorm.Config{
|
db, err = gorm.Open(postgres.Open(h.dbString), &gorm.Config{
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
DisableForeignKeyConstraintWhenMigrating: true,
|
||||||
Logger: log,
|
Logger: log,
|
||||||
|
|
Loading…
Reference in a new issue