diff --git a/.golangci.yaml b/.golangci.yaml index a68f535..b97922b 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 da4e8aa..9c66ca2 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 b3490ef..da81e30 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,