Fixed some warnings provided by jetbrains goland IDE

This commit is contained in:
Philipp Häfelfinger 2019-04-08 23:56:01 +02:00
parent 1c5552e690
commit 04b32dcd02
10 changed files with 69 additions and 205 deletions

View File

@ -20,9 +20,9 @@ type appContext struct {
localRootPath string localRootPath string
} }
func (c *appContext) UseMetadataStore(connectionString string) error { func (c *appContext) useMetadataStore(connectionString string) error {
if connectionString == "" { if connectionString == "" {
return errors.New("missing connectionString to use metadata store!") return errors.New("missing connectionString to use metadata store")
} }
logrus.Infof("Using SQL Lite data store with '%s'", connectionString) logrus.Infof("Using SQL Lite data store with '%s'", connectionString)
@ -32,17 +32,17 @@ func (c *appContext) UseMetadataStore(connectionString string) error {
return err return err
} }
func (c *appContext) UsePiwigo(url string, user string, password string) error { func (c *appContext) usePiwigo(url string, user string, password string) error {
if url == "" { if url == "" {
return errors.New("missing piwigo url!") return errors.New("missing piwigo url")
} }
if user == "" { if user == "" {
return errors.New("missing piwigo user!") return errors.New("missing piwigo user")
} }
if password == "" { if password == "" {
return errors.New("missing piwigo password!") return errors.New("missing piwigo password")
} }
c.piwigo = new(piwigo.PiwigoContext) c.piwigo = new(piwigo.PiwigoContext)
@ -56,7 +56,7 @@ func newAppContext() (*appContext, error) {
context.localRootPath = *imagesRootPath context.localRootPath = *imagesRootPath
if *sqliteDb != "" { if *sqliteDb != "" {
err := context.UseMetadataStore(*sqliteDb) err := context.useMetadataStore(*sqliteDb)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -64,7 +64,7 @@ func newAppContext() (*appContext, error) {
logrus.Warnln("No persistence configured. Skipping metadata storage. This might affect performance on large collections!") logrus.Warnln("No persistence configured. Skipping metadata storage. This might affect performance on large collections!")
} }
err := context.UsePiwigo(*piwigoUrl, *piwigoUser, *piwigoPassword) err := context.usePiwigo(*piwigoUrl, *piwigoUser, *piwigoPassword)
return context, err return context, err
} }

View File

@ -15,7 +15,7 @@ import (
"time" "time"
) )
//go:generate mockgen -destination=./piwigo_mock_test.go -package=category git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo PiwigoApi,PiwigoCategoryApi,PiwigoImageApi //go:generate mockgen -destination=./piwigo_mock_test.go -package=category git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo PiwigoCategoryApi,PiwigoImageApi
//go:generate mockgen -destination=./datastore_mock_test.go -package=category git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore CategoryProvider //go:generate mockgen -destination=./datastore_mock_test.go -package=category git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore CategoryProvider
func Test_updatePiwigoCategoriesFromServer_adds_new_categories(t *testing.T) { func Test_updatePiwigoCategoriesFromServer_adds_new_categories(t *testing.T) {
@ -320,7 +320,7 @@ func createDbSubCategory() datastore.CategoryData {
return category return category
} }
func createDbCategoriesFrom(categories map[string]*piwigo.PiwigoCategory) []datastore.CategoryData { func createDbCategoriesFrom(categories map[string]*piwigo.Category) []datastore.CategoryData {
var dbCategories []datastore.CategoryData var dbCategories []datastore.CategoryData
for _, cat := range categories { for _, cat := range categories {
dbCat := datastore.CategoryData{ dbCat := datastore.CategoryData{
@ -335,20 +335,20 @@ func createDbCategoriesFrom(categories map[string]*piwigo.PiwigoCategory) []data
return dbCategories return dbCategories
} }
func createTwoServerCategories() map[string]*piwigo.PiwigoCategory { func createTwoServerCategories() map[string]*piwigo.Category {
piwigoCategory1 := piwigo.PiwigoCategory{ piwigoCategory1 := piwigo.Category{
Id: 1, Id: 1,
Name: "2019", Name: "2019",
Key: "2019", Key: "2019",
ParentId: 0, ParentId: 0,
} }
piwigoCategory2 := piwigo.PiwigoCategory{ piwigoCategory2 := piwigo.Category{
Id: 2, Id: 2,
Name: "SubCategory", Name: "SubCategory",
Key: "2019/SubCategory", Key: "2019/SubCategory",
ParentId: 1, ParentId: 1,
} }
piwigoCategories := make(map[string]*piwigo.PiwigoCategory) piwigoCategories := make(map[string]*piwigo.Category)
piwigoCategories[piwigoCategory1.Key] = &piwigoCategory1 piwigoCategories[piwigoCategory1.Key] = &piwigoCategory1
piwigoCategories[piwigoCategory2.Key] = &piwigoCategory2 piwigoCategories[piwigoCategory2.Key] = &piwigoCategory2
return piwigoCategories return piwigoCategories

View File

@ -1,5 +1,5 @@
// Code generated by MockGen. DO NOT EDIT. // Code generated by MockGen. DO NOT EDIT.
// Source: git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo (interfaces: PiwigoApi,PiwigoCategoryApi,PiwigoImageApi) // Source: git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo (interfaces: PiwigoCategoryApi,PiwigoImageApi)
// Package category is a generated GoMock package. // Package category is a generated GoMock package.
package category package category
@ -10,71 +10,6 @@ import (
reflect "reflect" reflect "reflect"
) )
// MockPiwigoApi is a mock of PiwigoApi interface
type MockPiwigoApi struct {
ctrl *gomock.Controller
recorder *MockPiwigoApiMockRecorder
}
// MockPiwigoApiMockRecorder is the mock recorder for MockPiwigoApi
type MockPiwigoApiMockRecorder struct {
mock *MockPiwigoApi
}
// NewMockPiwigoApi creates a new mock instance
func NewMockPiwigoApi(ctrl *gomock.Controller) *MockPiwigoApi {
mock := &MockPiwigoApi{ctrl: ctrl}
mock.recorder = &MockPiwigoApiMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockPiwigoApi) EXPECT() *MockPiwigoApiMockRecorder {
return m.recorder
}
// Initialize mocks base method
func (m *MockPiwigoApi) Initialize(arg0, arg1, arg2 string, arg3 int) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Initialize", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(error)
return ret0
}
// Initialize indicates an expected call of Initialize
func (mr *MockPiwigoApiMockRecorder) Initialize(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Initialize", reflect.TypeOf((*MockPiwigoApi)(nil).Initialize), arg0, arg1, arg2, arg3)
}
// Login mocks base method
func (m *MockPiwigoApi) Login() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Login")
ret0, _ := ret[0].(error)
return ret0
}
// Login indicates an expected call of Login
func (mr *MockPiwigoApiMockRecorder) Login() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Login", reflect.TypeOf((*MockPiwigoApi)(nil).Login))
}
// Logout mocks base method
func (m *MockPiwigoApi) Logout() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Logout")
ret0, _ := ret[0].(error)
return ret0
}
// Logout indicates an expected call of Logout
func (mr *MockPiwigoApiMockRecorder) Logout() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Logout", reflect.TypeOf((*MockPiwigoApi)(nil).Logout))
}
// MockPiwigoCategoryApi is a mock of PiwigoCategoryApi interface // MockPiwigoCategoryApi is a mock of PiwigoCategoryApi interface
type MockPiwigoCategoryApi struct { type MockPiwigoCategoryApi struct {
ctrl *gomock.Controller ctrl *gomock.Controller
@ -114,10 +49,10 @@ func (mr *MockPiwigoCategoryApiMockRecorder) CreateCategory(arg0, arg1 interface
} }
// GetAllCategories mocks base method // GetAllCategories mocks base method
func (m *MockPiwigoCategoryApi) GetAllCategories() (map[string]*piwigo.PiwigoCategory, error) { func (m *MockPiwigoCategoryApi) GetAllCategories() (map[string]*piwigo.Category, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllCategories") ret := m.ctrl.Call(m, "GetAllCategories")
ret0, _ := ret[0].(map[string]*piwigo.PiwigoCategory) ret0, _ := ret[0].(map[string]*piwigo.Category)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }

View File

@ -14,7 +14,7 @@ import (
"time" "time"
) )
var ErrorRecordNotFound = errors.New("Record not found") var ErrorRecordNotFound = errors.New("record not found")
type CategoryData struct { type CategoryData struct {
CategoryId int CategoryId int
@ -72,7 +72,7 @@ func NewLocalDataStore() *LocalDataStore {
func (d *LocalDataStore) Initialize(connectionString string) error { func (d *LocalDataStore) Initialize(connectionString string) error {
if connectionString == "" { if connectionString == "" {
return errors.New("connection string could not be empty.") return errors.New("connection string could not be empty")
} }
d.connectionString = connectionString d.connectionString = connectionString
@ -137,7 +137,7 @@ func (d *LocalDataStore) ImageMetadataAll() ([]ImageMetaData, error) {
} }
defer rows.Close() defer rows.Close()
images := []ImageMetaData{} var images []ImageMetaData
for rows.Next() { for rows.Next() {
img := &ImageMetaData{} img := &ImageMetaData{}
err = readImageMetadataFromRow(rows, img) err = readImageMetadataFromRow(rows, img)
@ -166,7 +166,7 @@ func (d *LocalDataStore) ImageMetadataToDelete() ([]ImageMetaData, error) {
} }
defer rows.Close() defer rows.Close()
images := []ImageMetaData{} var images []ImageMetaData
for rows.Next() { for rows.Next() {
img := &ImageMetaData{} img := &ImageMetaData{}
err = readImageMetadataFromRow(rows, img) err = readImageMetadataFromRow(rows, img)
@ -195,7 +195,7 @@ func (d *LocalDataStore) ImageMetadataToUpload() ([]ImageMetaData, error) {
} }
defer rows.Close() defer rows.Close()
images := []ImageMetaData{} var images []ImageMetaData
for rows.Next() { for rows.Next() {
img := &ImageMetaData{} img := &ImageMetaData{}
err = readImageMetadataFromRow(rows, img) err = readImageMetadataFromRow(rows, img)

View File

@ -59,7 +59,7 @@ func Test_deleteImages_should_not_call_anything_if_no_images_are_marked_for_dele
mockCtrl := gomock.NewController(t) mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish() defer mockCtrl.Finish()
images := []datastore.ImageMetaData{} var images []datastore.ImageMetaData
dbmock := NewMockImageMetadataProvider(mockCtrl) dbmock := NewMockImageMetadataProvider(mockCtrl)
dbmock.EXPECT().ImageMetadataToDelete().Times(1).Return(images, nil) dbmock.EXPECT().ImageMetadataToDelete().Times(1).Return(images, nil)

View File

@ -1,5 +1,5 @@
// Code generated by MockGen. DO NOT EDIT. // Code generated by MockGen. DO NOT EDIT.
// Source: git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo (interfaces: PiwigoApi,PiwigoCategoryApi,PiwigoImageApi) // Source: git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo (interfaces: PiwigoCategoryApi,PiwigoImageApi)
// Package images is a generated GoMock package. // Package images is a generated GoMock package.
package images package images
@ -10,71 +10,6 @@ import (
reflect "reflect" reflect "reflect"
) )
// MockPiwigoApi is a mock of PiwigoApi interface
type MockPiwigoApi struct {
ctrl *gomock.Controller
recorder *MockPiwigoApiMockRecorder
}
// MockPiwigoApiMockRecorder is the mock recorder for MockPiwigoApi
type MockPiwigoApiMockRecorder struct {
mock *MockPiwigoApi
}
// NewMockPiwigoApi creates a new mock instance
func NewMockPiwigoApi(ctrl *gomock.Controller) *MockPiwigoApi {
mock := &MockPiwigoApi{ctrl: ctrl}
mock.recorder = &MockPiwigoApiMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockPiwigoApi) EXPECT() *MockPiwigoApiMockRecorder {
return m.recorder
}
// Initialize mocks base method
func (m *MockPiwigoApi) Initialize(arg0, arg1, arg2 string, arg3 int) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Initialize", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(error)
return ret0
}
// Initialize indicates an expected call of Initialize
func (mr *MockPiwigoApiMockRecorder) Initialize(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Initialize", reflect.TypeOf((*MockPiwigoApi)(nil).Initialize), arg0, arg1, arg2, arg3)
}
// Login mocks base method
func (m *MockPiwigoApi) Login() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Login")
ret0, _ := ret[0].(error)
return ret0
}
// Login indicates an expected call of Login
func (mr *MockPiwigoApiMockRecorder) Login() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Login", reflect.TypeOf((*MockPiwigoApi)(nil).Login))
}
// Logout mocks base method
func (m *MockPiwigoApi) Logout() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Logout")
ret0, _ := ret[0].(error)
return ret0
}
// Logout indicates an expected call of Logout
func (mr *MockPiwigoApiMockRecorder) Logout() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Logout", reflect.TypeOf((*MockPiwigoApi)(nil).Logout))
}
// MockPiwigoCategoryApi is a mock of PiwigoCategoryApi interface // MockPiwigoCategoryApi is a mock of PiwigoCategoryApi interface
type MockPiwigoCategoryApi struct { type MockPiwigoCategoryApi struct {
ctrl *gomock.Controller ctrl *gomock.Controller
@ -114,10 +49,10 @@ func (mr *MockPiwigoCategoryApiMockRecorder) CreateCategory(arg0, arg1 interface
} }
// GetAllCategories mocks base method // GetAllCategories mocks base method
func (m *MockPiwigoCategoryApi) GetAllCategories() (map[string]*piwigo.PiwigoCategory, error) { func (m *MockPiwigoCategoryApi) GetAllCategories() (map[string]*piwigo.Category, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllCategories") ret := m.ctrl.Call(m, "GetAllCategories")
ret0, _ := ret[0].(map[string]*piwigo.PiwigoCategory) ret0, _ := ret[0].(map[string]*piwigo.Category)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }

View File

@ -5,7 +5,7 @@
package images package images
//go:generate mockgen -destination=./piwigo_mock_test.go -package=images git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo PiwigoApi,PiwigoCategoryApi,PiwigoImageApi //go:generate mockgen -destination=./piwigo_mock_test.go -package=images git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo PiwigoCategoryApi,PiwigoImageApi
//go:generate mockgen -destination=./datastore_mock_test.go -package=images git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore ImageMetadataProvider,CategoryProvider //go:generate mockgen -destination=./datastore_mock_test.go -package=images git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore ImageMetadataProvider,CategoryProvider
import ( import (

View File

@ -36,7 +36,7 @@ func Test_checkPiwigoForChangedImages_with_empty_list(t *testing.T) {
mockCtrl := gomock.NewController(t) mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish() defer mockCtrl.Finish()
images := []datastore.ImageMetaData{} var images []datastore.ImageMetaData
dbmock := NewMockImageMetadataProvider(mockCtrl) dbmock := NewMockImageMetadataProvider(mockCtrl)
dbmock.EXPECT().ImageMetadataToUpload().Return(images, nil) dbmock.EXPECT().ImageMetadataToUpload().Return(images, nil)
@ -106,7 +106,7 @@ func Test_updatePiwigoIdIfAlreadyUploaded_without_images_to_upload(t *testing.T)
mockCtrl := gomock.NewController(t) mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish() defer mockCtrl.Finish()
images := []datastore.ImageMetaData{} var images []datastore.ImageMetaData
dbmock := NewMockImageMetadataProvider(mockCtrl) dbmock := NewMockImageMetadataProvider(mockCtrl)
dbmock.EXPECT().ImageMetadataToUpload().Return(images, nil) dbmock.EXPECT().ImageMetadataToUpload().Return(images, nil)

View File

@ -18,7 +18,7 @@ import (
) )
const ( const (
ImageStateInvalid = -1 imageStateInvalid = -1
ImageStateUptodate = 0 ImageStateUptodate = 0
ImageStateDifferent = 1 ImageStateDifferent = 1
) )
@ -71,11 +71,11 @@ func uploadImageChunk(context *PiwigoContext, base64chunk string, md5sum string,
logrus.Tracef("Uploading chunk %d of file with sum %s", position, md5sum) logrus.Tracef("Uploading chunk %d of file with sum %s", position, md5sum)
var uploadChunkResponse uploadChunkResponse var response uploadChunkResponse
err := context.executePiwigoRequest(formData, &uploadChunkResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
logrus.Errorf("Got state %s while uploading chunk %d of %s", uploadChunkResponse.Status, position, md5sum) logrus.Errorf("Got state %s while uploading chunk %d of %s", response.Status, position, md5sum)
return errors.New(fmt.Sprintf("Got state %s while uploading chunk %d of %s", uploadChunkResponse.Status, position, md5sum)) return errors.New(fmt.Sprintf("Got state %s while uploading chunk %d of %s", response.Status, position, md5sum))
} }
return nil return nil
@ -97,12 +97,12 @@ func uploadImageFinal(context *PiwigoContext, piwigoId int, originalFilename str
logrus.Debugf("Finalizing upload of file %s with sum %s to category %d", originalFilename, md5sum, categoryId) logrus.Debugf("Finalizing upload of file %s with sum %s to category %d", originalFilename, md5sum, categoryId)
var fileAddResponse fileAddResponse var response fileAddResponse
err := context.executePiwigoRequest(formData, &fileAddResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
logrus.Errorf("Got state %s while adding image %s", fileAddResponse.Status, originalFilename) logrus.Errorf("Got state %s while adding image %s", response.Status, originalFilename)
return 0, errors.New(fmt.Sprintf("Got state %s while adding image %s", fileAddResponse.Status, originalFilename)) return 0, errors.New(fmt.Sprintf("Got state %s while adding image %s", response.Status, originalFilename))
} }
return fileAddResponse.Result.ImageID, nil return response.Result.ImageID, nil
} }

View File

@ -18,12 +18,6 @@ import (
"strings" "strings"
) )
type PiwigoApi interface {
Initialize(baseUrl string, username string, password string, chunkSizeInKB int) error
Login() error
Logout() error
}
type PiwigoCategoryApi interface { type PiwigoCategoryApi interface {
GetAllCategories() (map[string]*PiwigoCategory, error) GetAllCategories() (map[string]*PiwigoCategory, error)
CreateCategory(parentId int, name string) (int, error) CreateCategory(parentId int, name string) (int, error)
@ -46,7 +40,7 @@ type PiwigoContext struct {
func (context *PiwigoContext) Initialize(baseUrl string, username string, password string) error { func (context *PiwigoContext) Initialize(baseUrl string, username string, password string) error {
if baseUrl == "" { if baseUrl == "" {
return errors.New("Please provide a valid piwigo server base URL") return errors.New("please provide a valid piwigo server base URL")
} }
_, err := url.Parse(baseUrl) _, err := url.Parse(baseUrl)
if err != nil { if err != nil {
@ -54,7 +48,7 @@ func (context *PiwigoContext) Initialize(baseUrl string, username string, passwo
} }
if username == "" { if username == "" {
return errors.New("Please provide a valid username for the given piwigo server.") return errors.New("please provide a valid username for the given piwigo server")
} }
context.url = fmt.Sprintf("%s/ws.php?format=json", baseUrl) context.url = fmt.Sprintf("%s/ws.php?format=json", baseUrl)
@ -78,15 +72,15 @@ func (context *PiwigoContext) Login() error {
formData.Set("username", context.username) formData.Set("username", context.username)
formData.Set("password", context.password) formData.Set("password", context.password)
var loginResponse loginResponse var response loginResponse
err := context.executePiwigoRequest(formData, &loginResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
errorMessage := fmt.Sprintf("Login failed: %d - %s", loginResponse.ErrorNumber, loginResponse.Message) errorMessage := fmt.Sprintf("Login failed: %d - %s", response.ErrorNumber, response.Message)
logrus.Errorln(errorMessage) logrus.Errorln(errorMessage)
return errors.New(errorMessage) return errors.New(errorMessage)
} }
logrus.Infof("Login succeeded: %s", loginResponse.Status) logrus.Infof("Login succeeded: %s", response.Status)
return context.initializeUploadChunkSize() return context.initializeUploadChunkSize()
} }
@ -96,8 +90,8 @@ func (context *PiwigoContext) Logout() error {
formData := url.Values{} formData := url.Values{}
formData.Set("method", "pwg.session.logout") formData.Set("method", "pwg.session.logout")
var logoutResponse logoutResponse var response logoutResponse
err := context.executePiwigoRequest(formData, &logoutResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
logrus.Errorf("Logout from %s failed", context.url) logrus.Errorf("Logout from %s failed", context.url)
return err return err
@ -113,15 +107,15 @@ func (context *PiwigoContext) getStatus() (*getStatusResponse, error) {
formData := url.Values{} formData := url.Values{}
formData.Set("method", "pwg.session.getStatus") formData.Set("method", "pwg.session.getStatus")
var getStatusResponse getStatusResponse var response getStatusResponse
err := context.executePiwigoRequest(formData, &getStatusResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
errorMessage := fmt.Sprintln("Could not get session state from server") errorMessage := fmt.Sprintln("Could not get session state from server")
logrus.Errorln(errorMessage) logrus.Errorln(errorMessage)
return nil, errors.New(errorMessage) return nil, errors.New(errorMessage)
} }
return &getStatusResponse, nil return &response, nil
} }
func (context *PiwigoContext) GetAllCategories() (map[string]*PiwigoCategory, error) { func (context *PiwigoContext) GetAllCategories() (map[string]*PiwigoCategory, error) {
@ -129,15 +123,15 @@ func (context *PiwigoContext) GetAllCategories() (map[string]*PiwigoCategory, er
formData.Set("method", "pwg.categories.getList") formData.Set("method", "pwg.categories.getList")
formData.Set("recursive", "true") formData.Set("recursive", "true")
var getCategoryListResponse getCategoryListResponse var response getCategoryListResponse
err := context.executePiwigoRequest(formData, &getCategoryListResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
logrus.Errorf("Got error while loading categories: %s", err) logrus.Errorf("Got error while loading categories: %s", err)
return nil, errors.New("Could not load categories") return nil, errors.New("could not load categories")
} }
logrus.Infof("Successfully got all categories") logrus.Infof("Successfully got all categories")
categories := buildCategoryMap(&getCategoryListResponse) categories := buildCategoryMap(&response)
buildCategoryKeys(categories) buildCategoryKeys(categories)
categoryLookups := buildLookupMap(categories) categoryLookups := buildLookupMap(categories)
@ -154,15 +148,15 @@ func (context *PiwigoContext) CreateCategory(parentId int, name string) (int, er
formData.Set("parent", fmt.Sprint(parentId)) formData.Set("parent", fmt.Sprint(parentId))
} }
var createCategoryResponse createCategoryResponse var response createCategoryResponse
err := context.executePiwigoRequest(formData, &createCategoryResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
logrus.Errorln(err) logrus.Errorln(err)
return 0, err return 0, err
} }
logrus.Infof("Successfully created category %s with id %d", name, createCategoryResponse.Result.ID) logrus.Infof("Successfully created category %s with id %d", name, response.Result.ID)
return createCategoryResponse.Result.ID, nil return response.Result.ID, nil
} }
func (context *PiwigoContext) ImageCheckFile(piwigoId int, md5sum string) (int, error) { func (context *PiwigoContext) ImageCheckFile(piwigoId int, md5sum string) (int, error) {
@ -173,13 +167,13 @@ func (context *PiwigoContext) ImageCheckFile(piwigoId int, md5sum string) (int,
logrus.Tracef("Checking if file %s - %d needs to be uploaded", md5sum, piwigoId) logrus.Tracef("Checking if file %s - %d needs to be uploaded", md5sum, piwigoId)
var checkFilesResponse checkFilesResponse var response checkFilesResponse
err := context.executePiwigoRequest(formData, &checkFilesResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
return ImageStateInvalid, err return imageStateInvalid, err
} }
if checkFilesResponse.Result["file"] == "equals" { if response.Result["file"] == "equals" {
return ImageStateUptodate, nil return ImageStateUptodate, nil
} }
return ImageStateDifferent, nil return ImageStateDifferent, nil
@ -212,13 +206,13 @@ func (context *PiwigoContext) imagesExistOnPiwigoBatch(md5sums []string, existRe
logrus.Tracef("Looking up if files exist: %s", md5sumList) logrus.Tracef("Looking up if files exist: %s", md5sumList)
var imageExistResponse imageExistResponse var response imageExistResponse
err := context.executePiwigoRequest(formData, &imageExistResponse) err := context.executePiwigoRequest(formData, &response)
if err != nil { if err != nil {
return err return err
} }
for key, value := range imageExistResponse.Result { for key, value := range response.Result {
if value == "" { if value == "" {
logrus.Tracef("Missing file with md5sum: %s", key) logrus.Tracef("Missing file with md5sum: %s", key)
existResults[key] = 0 existResults[key] = 0
@ -238,7 +232,7 @@ func (context *PiwigoContext) imagesExistOnPiwigoBatch(md5sums []string, existRe
func (context *PiwigoContext) UploadImage(piwigoId int, filePath string, md5sum string, category int) (int, error) { func (context *PiwigoContext) UploadImage(piwigoId int, filePath string, md5sum string, category int) (int, error) {
if context.chunkSizeInKB <= 0 { if context.chunkSizeInKB <= 0 {
return 0, errors.New("Uploadchunk size is less or equal to zero. 512 is a recommendet value to begin with.") return 0, errors.New("uploadchunk size is less or equal to zero. 512 is a recommendet value to begin with")
} }
fileInfo, err := os.Stat(filePath) fileInfo, err := os.Stat(filePath)
@ -284,8 +278,8 @@ func (context *PiwigoContext) DeleteImages(imageIds []int) error {
formData.Set("image_id", joinedIds) formData.Set("image_id", joinedIds)
formData.Set("pwg_token", pwgToken) formData.Set("pwg_token", pwgToken)
var deleteResponse deleteResponse var response deleteResponse
return context.executePiwigoRequest(formData, &deleteResponse) return context.executePiwigoRequest(formData, &response)
} }
func (context *PiwigoContext) getPiwigoToken() (string, error) { func (context *PiwigoContext) getPiwigoToken() (string, error) {
@ -299,7 +293,7 @@ func (context *PiwigoContext) getPiwigoToken() (string, error) {
} }
pwgToken := status.Result.PwgToken pwgToken := status.Result.PwgToken
if pwgToken == "" { if pwgToken == "" {
return "", errors.New("Did not get a valid piwigo token. Could not delete the images.") return "", errors.New("did not get a valid piwigo token. Could not delete the images")
} }
return pwgToken, nil return pwgToken, nil
} }