diff options
Diffstat (limited to 'cmd/dbasik-api/main.go')
-rw-r--r-- | cmd/dbasik-api/main.go | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/cmd/dbasik-api/main.go b/cmd/dbasik-api/main.go index b4850f8..066c2e6 100644 --- a/cmd/dbasik-api/main.go +++ b/cmd/dbasik-api/main.go @@ -32,7 +32,7 @@ import ( "time" "github.com/joho/godotenv" - _ "github.com/lib/pq" + _ "github.com/mattn/go-sqlite3" ) const version = "0.0.1" @@ -42,12 +42,7 @@ const version = "0.0.1" type config struct { port int env string - db struct { - dsn string - maxOpenConns int - maxIdleConns int - maxIdleTime string - } + db string } // This application struct holds the dependencies for our HTTP handlers, helpers and @@ -70,12 +65,7 @@ func main() { // Read the flags into the config struct. Defaults are provided if none given. flag.IntVar(&cfg.port, "port", 5000, "API server port") flag.StringVar(&cfg.env, "env", "development", "Environment (development|staging|production)") - flag.StringVar(&cfg.db.dsn, "db-dsn", os.Getenv("DBASIK_DB_DSN"), "PostgreSQL DSN") - - //Read connection pool settings (explained in Configuring the pool in the book) - flag.IntVar(&cfg.db.maxOpenConns, "db-max-open-conns", 25, "PostgreSQL max open connections") - flag.IntVar(&cfg.db.maxIdleConns, "db-max-idle-conns", 25, "PostgreSQL max idle connections") - flag.StringVar(&cfg.db.maxIdleTime, "db-max-idle-time", "15m", "PostgreSQL max connection idle time") + flag.StringVar(&cfg.db, "db-dsn", os.Getenv("DBASIK_DB_DSN"), "sqlite3 DSN") flag.Parse() @@ -118,19 +108,10 @@ func main() { } func openDB(cfg config) (*sql.DB, error) { - db, err := sql.Open("postgres", cfg.db.dsn) - if err != nil { - return nil, err - } - - // set up pool config - db.SetMaxOpenConns(cfg.db.maxOpenConns) - db.SetMaxIdleConns(cfg.db.maxIdleConns) - duration, err := time.ParseDuration(cfg.db.maxIdleTime) + db, err := sql.Open("sqlite3", cfg.db) if err != nil { return nil, err } - db.SetConnMaxIdleTime(duration) // create a context with a 5 second timeout // if the database hasn't connected within this time, there is a problem |