From 9390348a65597119c7c958bdb66c8ad54177c3de Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 14 Nov 2021 18:06:25 +0100 Subject: [PATCH] Add and fix goconst --- .golangci.yaml | 1 - app.go | 6 ++++-- db.go | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index a68f5359..b97922b1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -39,7 +39,6 @@ linters: - gocritic - forbidigo - dupl - - goconst - varnamelen - makezero - paralleltest diff --git a/app.go b/app.go index da4e8aa6..9c66ca21 100644 --- a/app.go +++ b/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") diff --git a/db.go b/db.go index b3490ef9..da81e301 100644 --- a/db.go +++ b/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,