go fmt
This commit is contained in:
@@ -25,4 +25,4 @@ func (r *albumRepository) Get(id string) (*domain.Album, error) {
|
||||
var rec interface{}
|
||||
rec, err := r.readEntity(id)
|
||||
return rec.(*domain.Album), err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,3 @@ func (r *artistRepository) GetByName(name string) (*domain.Artist, error) {
|
||||
id := r.NewId(name)
|
||||
return r.Get(id)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"crypto/md5"
|
||||
"strings"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type baseRepository struct {
|
||||
@@ -90,7 +90,7 @@ func (r *baseRepository) getFieldKeys(id string) [][]byte {
|
||||
return fieldKeys
|
||||
}
|
||||
|
||||
func (r*baseRepository) newInstance() interface{} {
|
||||
func (r *baseRepository) newInstance() interface{} {
|
||||
return reflect.New(r.entityType).Interface()
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func (r *baseRepository) toEntity(response [][]byte, entity interface{}) error {
|
||||
// TODO Optimize it! Probably very slow (and confusing!)
|
||||
func (r *baseRepository) loadAll(entities interface{}, sortBy string) error {
|
||||
total, err := r.CountAll()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ func (r *baseRepository) loadAll(entities interface{}, sortBy string) error {
|
||||
}
|
||||
setName := r.table + "s:all"
|
||||
response, err := db().XSSort([]byte(setName), 0, 0, true, false, sortKey, r.getFieldKeys("*"))
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
numFields := len(r.fieldNames)
|
||||
@@ -142,7 +142,7 @@ func (r *baseRepository) loadAll(entities interface{}, sortBy string) error {
|
||||
start := i * numFields
|
||||
entity := reflect.New(r.entityType).Interface()
|
||||
|
||||
if err := r.toEntity(response[start:start + numFields], entity); err != nil {
|
||||
if err := r.toEntity(response[start:start+numFields], entity); err != nil {
|
||||
return err
|
||||
}
|
||||
reflected.Set(reflect.Append(reflected, reflect.ValueOf(entity).Elem()))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"testing"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/tests"
|
||||
"fmt"
|
||||
"github.com/deluan/gosonic/tests"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type TestEntity struct {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"errors"
|
||||
"sort"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type artistIndex struct {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"testing"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/tests"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"strconv"
|
||||
"github.com/deluan/gosonic/tests"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIndexRepository(t *testing.T) {
|
||||
@@ -19,7 +19,7 @@ func TestIndexRepository(t *testing.T) {
|
||||
i := &domain.ArtistIndex{Id: "123"}
|
||||
|
||||
repo.Put(i)
|
||||
s,_ := repo.Get("123")
|
||||
s, _ := repo.Get("123")
|
||||
|
||||
So(s, shouldBeEqual, i)
|
||||
})
|
||||
@@ -37,7 +37,7 @@ func TestIndexRepository(t *testing.T) {
|
||||
}
|
||||
|
||||
Convey("When I call GetAll()", func() {
|
||||
indices, err := repo.GetAll()
|
||||
indices, err := repo.GetAll()
|
||||
Convey("Then It should not return any error", func() {
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
@@ -55,4 +55,4 @@ func TestIndexRepository(t *testing.T) {
|
||||
dropDb()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"github.com/siddontang/ledisdb/config"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
_ledisInstance *ledis.Ledis
|
||||
_dbInstance *ledis.DB
|
||||
once sync.Once
|
||||
_dbInstance *ledis.DB
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func db() *ledis.DB {
|
||||
@@ -28,8 +28,7 @@ func db() *ledis.DB {
|
||||
return _dbInstance
|
||||
}
|
||||
|
||||
|
||||
func dropDb() {
|
||||
db()
|
||||
_ledisInstance.FlushAll()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@ func NewMediaFileRepository() domain.MediaFileRepository {
|
||||
|
||||
func (r *mediaFileRepository) Put(m *domain.MediaFile) error {
|
||||
return r.saveOrUpdate(m.Id, m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
)
|
||||
|
||||
type mediaFolderRepository struct {
|
||||
@@ -13,10 +13,9 @@ func NewMediaFolderRepository() domain.MediaFolderRepository {
|
||||
return &mediaFolderRepository{}
|
||||
}
|
||||
|
||||
|
||||
func (*mediaFolderRepository) GetAll() ([]domain.MediaFolder, error) {
|
||||
mediaFolder := domain.MediaFolder{Id: "0", Name: "iTunes Library", Path: beego.AppConfig.String("musicFolder")}
|
||||
result := make([]domain.MediaFolder, 1)
|
||||
result[0] = mediaFolder
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type propertyRepository struct {
|
||||
@@ -29,7 +29,7 @@ func (r *propertyRepository) Get(id string) (string, error) {
|
||||
return rec.(*domain.Property).Value, err
|
||||
}
|
||||
|
||||
func (r*propertyRepository) DefaultGet(id string, defaultValue string) (string, error) {
|
||||
func (r *propertyRepository) DefaultGet(id string, defaultValue string) (string, error) {
|
||||
v, err := r.Get(id)
|
||||
|
||||
if v == "" {
|
||||
|
||||
Reference in New Issue
Block a user