|
|
@ -8,18 +8,17 @@ package seaweed
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/kataras/pio"
|
|
|
|
// "github.com/kataras/pio"
|
|
|
|
|
|
|
|
"github.com/kataras/golog"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// глобальная переменная для логирования
|
|
|
|
const VERSION = "v1.0.7"
|
|
|
|
var p = pio.NewTextPrinter("color", os.Stdout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ============= SEA ============
|
|
|
|
// ============= SEA ============
|
|
|
|
|
|
|
|
|
|
|
@ -29,9 +28,11 @@ type Sea struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Connect to database and connect to weed
|
|
|
|
// Connect to database and connect to weed
|
|
|
|
func Connect() (*Sea, error) {
|
|
|
|
func Connect(options ...bool) (*Sea, error) {
|
|
|
|
debug := flag.Bool("debug", false, "enable debug mode")
|
|
|
|
debug := false
|
|
|
|
fmt.Printf("debug: %v\n", *debug)
|
|
|
|
if len(options) > 0 && options[0] == true {
|
|
|
|
|
|
|
|
debug = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
user := os.Getenv("SEA_USER")
|
|
|
|
user := os.Getenv("SEA_USER")
|
|
|
|
if user == "" {
|
|
|
|
if user == "" {
|
|
|
@ -48,11 +49,12 @@ func Connect() (*Sea, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if *debug {
|
|
|
|
sea := Sea{db: db, debug: debug}
|
|
|
|
p.Println(pio.Rich("БД sea успешно открыта", pio.Blue))
|
|
|
|
|
|
|
|
|
|
|
|
if debug {
|
|
|
|
|
|
|
|
golog.Infof("БД \"sea\" успешно открыта. %s", VERSION)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sea := Sea{db: db, debug: *debug}
|
|
|
|
|
|
|
|
return &sea, nil
|
|
|
|
return &sea, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -83,5 +85,9 @@ func (s *Sea) Albums() ([]Album, error) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.debug {
|
|
|
|
|
|
|
|
golog.Infof("Получен список альбомов: %d", len(albums))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return albums, nil
|
|
|
|
return albums, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|