package database import ( "database/sql" "log" "os" _ "github.com/joho/godotenv/autoload" _ "github.com/mattn/go-sqlite3" ) type Service interface { Close() error } type service struct { db *sql.DB } var ( dburl = os.Getenv("BLUEPRINT_DB_URL") dbInstance *service ) func New() Service { if dbInstance != nil { return dbInstance } db, err := sql.Open("sqlite3", dburl) if err != nil { log.Fatal(err) } dbInstance = &service{ db: db, } return dbInstance } func (s *service) Close() error { log.Printf("Disconnected from database: %s", dburl) return s.db.Close() }