|
|
@ -1,21 +1,36 @@
|
|
|
|
package sea
|
|
|
|
package sea
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
|
|
Пакет sea предназначен для облегчения работы с БД sea
|
|
|
|
|
|
|
|
и weed.
|
|
|
|
|
|
|
|
Текущая версия: v1.0.4
|
|
|
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/kataras/pio"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// глобальная переменная для логирования
|
|
|
|
|
|
|
|
var p = pio.NewTextPrinter("color", os.Stdout)
|
|
|
|
|
|
|
|
|
|
|
|
// ============= SEA ============
|
|
|
|
// ============= SEA ============
|
|
|
|
|
|
|
|
|
|
|
|
type Sea struct {
|
|
|
|
type Sea struct {
|
|
|
|
db *sqlx.DB
|
|
|
|
db *sqlx.DB
|
|
|
|
|
|
|
|
debug bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Connect() (*Sea, error) {
|
|
|
|
func Connect() (*Sea, error) {
|
|
|
|
|
|
|
|
debug := flag.Bool("debug", false, "enable debug mode")
|
|
|
|
|
|
|
|
|
|
|
|
user := os.Getenv("SEA_USER")
|
|
|
|
user := os.Getenv("SEA_USER")
|
|
|
|
if user == "" {
|
|
|
|
if user == "" {
|
|
|
|
return nil, errors.New("Не установлена переменная SEA_USER")
|
|
|
|
return nil, errors.New("Не установлена переменная SEA_USER")
|
|
|
@ -30,7 +45,12 @@ func Connect() (*Sea, error) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sea := Sea{db: db}
|
|
|
|
|
|
|
|
|
|
|
|
if *debug {
|
|
|
|
|
|
|
|
p.Println(pio.Rich("БД sea успешно открыта", pio.Blue))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sea := Sea{db: db, debug debug}
|
|
|
|
return &sea, nil
|
|
|
|
return &sea, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -45,12 +65,15 @@ func openDB(user, password string) (*sqlx.DB, error) {
|
|
|
|
|
|
|
|
|
|
|
|
// ============= ALBUM ============
|
|
|
|
// ============= ALBUM ============
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Album содержит информацию об активном альбоме
|
|
|
|
type Album struct {
|
|
|
|
type Album struct {
|
|
|
|
Seria string
|
|
|
|
Seria string
|
|
|
|
Cnt int
|
|
|
|
Cnt int
|
|
|
|
Hash string
|
|
|
|
Hash string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Albums возвращает список активных альбомов,
|
|
|
|
|
|
|
|
// без учета комиксов.
|
|
|
|
func (s *Sea) Albums() ([]Album, error) {
|
|
|
|
func (s *Sea) Albums() ([]Album, error) {
|
|
|
|
cmd := "call getAlbums()"
|
|
|
|
cmd := "call getAlbums()"
|
|
|
|
var albums []Album
|
|
|
|
var albums []Album
|
|
|
@ -61,4 +84,3 @@ func (s *Sea) Albums() ([]Album, error) {
|
|
|
|
return albums, nil
|
|
|
|
return albums, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|