Files
gocryptotrader/cmd/dbseed/database.go
dependabot[bot] 179519a3c3 golangci-lint: Bump to v2.0.2 and fix issues (#1871)
* build(deps): Bump golangci/golangci-lint-action from 6 to 7

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6 to 7.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v6...v7)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* golangci-lint: Bump to v2 and fix issues

* refactor: remove no longer need ifshort nolint directives, fix test grammar and improve for loop logic

* nits: update order pair handling in tests and improve string replacement logic

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
2025-04-02 15:36:05 +11:00

63 lines
1.5 KiB
Go

package main
import (
"fmt"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/database"
dbPSQL "github.com/thrasher-corp/gocryptotrader/database/drivers/postgres"
dbsqlite3 "github.com/thrasher-corp/gocryptotrader/database/drivers/sqlite3"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/urfave/cli/v2"
)
var dbConn *database.Instance
func load(c *cli.Context) error {
var conf config.Config
err := conf.LoadConfig(c.String("config"), true)
if err != nil {
return err
}
if !conf.Database.Enabled {
return database.ErrDatabaseSupportDisabled
}
err = openDBConnection(c, &conf.Database)
if err != nil {
return err
}
drv := repository.GetSQLDialect()
if drv == database.DBSQLite || drv == database.DBSQLite3 {
fmt.Printf("Database file: %s\n", conf.Database.Database)
} else {
fmt.Printf("Connected to: %s\n", conf.Database.Host)
}
return nil
}
func openDBConnection(c *cli.Context, cfg *database.Config) (err error) {
if c.IsSet("verbose") {
boil.DebugMode = true
}
switch cfg.Driver {
case database.DBPostgreSQL:
dbConn, err = dbPSQL.Connect(cfg)
case database.DBSQLite, database.DBSQLite3:
dbConn, err = dbsqlite3.Connect(cfg.Database)
default:
return fmt.Errorf("unsupported database driver: %q", cfg.Driver)
}
if err != nil {
return fmt.Errorf("database failed to connect: %w, some features that utilise a database will be unavailable", err)
}
return nil
}