From 60128ac0587bd1345ffeca0b5a259ddb080cf2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sun, 4 Feb 2024 16:20:36 +0500 Subject: [PATCH] =?UTF-8?q?v1.0.1=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20Sea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea.go | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/sea.go b/sea.go index 4150ec3..3c7b8e9 100644 --- a/sea.go +++ b/sea.go @@ -1,30 +1,45 @@ package sea import ( - "fmt" + // "fmt" _ "github.com/go-sql-driver/mysql" // для связи с mysql "github.com/jmoiron/sqlx" ) +// ============= SEA ============ + +type Sea struct { + db *sqlx.DB +} + +func Connect() (*Sea, error) { + db, err := openDB() + if err != nil { + return nil, err + } + sea := Sea{db: db} + return &sea, nil +} + +// ============= ALBUM ============ type Album struct { Seria string Cnt int Hash string } -func getAlbums(db *sqlx.DB) []Album { - cmd := "call getAlbums()" - var albums []Album - err := db.Select(&albums, cmd) - checkError("get albums", err) - - return albums -} +// func getAlbums(db *sqlx.DB) []Album { +// cmd := "call getAlbums()" +// var albums []Album +// err := db.Select(&albums, cmd) +// return albums +// } -func openDB() *sqlx.DB { - fmt.Printf("открываю БД sea\n") +func openDB() (*sqlx.DB, error) { db, err := sqlx.Open("mysql", "itman:X753951x@(xigmanas:3306)/sea") - checkError("open db", err) - return db + if err != nil { + return nil, err + } + return db, nil }