error handling one more time :-D

This commit is contained in:
Philipp Häfelfinger 2019-02-25 23:51:18 +01:00
parent 1fbf889a4b
commit 470df78264
3 changed files with 30 additions and 11 deletions

View File

@ -21,32 +21,32 @@ var (
func Run() { func Run() {
context, err := configureContext() context, err := configureContext()
if err != nil { if err != nil {
os.Exit(1) logErrorAndExit(err, 1)
} }
err = loginToPiwigoAndConfigureContext(context) err = loginToPiwigoAndConfigureContext(context)
if err != nil { if err != nil {
os.Exit(2) logErrorAndExit(err, 2)
} }
filesystemNodes, err := localFileStructure.ScanLocalFileStructure(context.LocalRootPath) filesystemNodes, err := localFileStructure.ScanLocalFileStructure(context.LocalRootPath)
if err != nil { if err != nil {
os.Exit(3) logErrorAndExit(err, 3)
} }
categories, err := getAllCategoriesFromServer(context) categories, err := getAllCategoriesFromServer(context)
if err != nil { if err != nil {
os.Exit(4) logErrorAndExit(err, 4)
} }
err = synchronizeCategories(filesystemNodes, categories) err = synchronizeCategories(filesystemNodes, categories)
if err != nil { if err != nil {
os.Exit(5) logErrorAndExit(err, 5)
} }
err = synchronizeImages() err = synchronizeImages()
if err != nil { if err != nil {
os.Exit(6) logErrorAndExit(err, 6)
} }
_ = authentication.Logout(context.Piwigo) _ = authentication.Logout(context.Piwigo)
@ -95,3 +95,8 @@ func initializeUploadChunkSize(context *AppContext) error {
logrus.Debugln(context.ChunkSizeBytes) logrus.Debugln(context.ChunkSizeBytes)
return nil return nil
} }
func logErrorAndExit(err error, exitCode int) {
logrus.Errorln(err)
os.Exit(exitCode)
}

View File

@ -1,6 +1,7 @@
package app package app
import ( import (
"errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/localFileStructure" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/localFileStructure"
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/category" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/category"
@ -48,10 +49,20 @@ func createMissingCategories(missingCategories []string, existingCategories map[
// in the right order and we have the parent available while creating the children // in the right order and we have the parent available while creating the children
sort.Strings(missingCategories) sort.Strings(missingCategories)
logrus.Warnln("Creating missing albums (NotImplemented)")
for _, c := range missingCategories { for _, c := range missingCategories {
logrus.Debug(c) logrus.Infof("Creating category %s",c)
// create category on piwigo
// build new map entry
// get parent entry by path
// set parent entry id
// calculate new map key
// add to existing map
} }
return nil return errors.New("NOT IMPLEMENTED")
} }

View File

@ -1,11 +1,14 @@
package app package app
import "github.com/sirupsen/logrus" import (
"errors"
"github.com/sirupsen/logrus"
)
func synchronizeImages() error { func synchronizeImages() error {
findMissingImages() findMissingImages()
uploadImages() uploadImages()
return nil return errors.New("NOT IMPLEMENTED")
} }
func findMissingImages() { func findMissingImages() {