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