made app context internal to the app parts

This commit is contained in:
Philipp Häfelfinger 2019-02-27 22:13:23 +01:00
parent 2808c85147
commit 45db2fe79b
4 changed files with 9 additions and 9 deletions

View File

@ -52,7 +52,7 @@ func Run() {
_ = authentication.Logout(context.Piwigo) _ = authentication.Logout(context.Piwigo)
} }
func configureContext() (*AppContext, error) { func configureContext() (*appContext, error) {
logrus.Infoln("Preparing application context and configuration") logrus.Infoln("Preparing application context and configuration")
if *piwigoUrl == "" { if *piwigoUrl == "" {
@ -67,7 +67,7 @@ func configureContext() (*AppContext, error) {
return nil, errors.New("missing piwigo password!") return nil, errors.New("missing piwigo password!")
} }
context := new(AppContext) context := new(appContext)
context.LocalRootPath = *imagesRootPath context.LocalRootPath = *imagesRootPath
context.Piwigo = new(piwigo.PiwigoContext) context.Piwigo = new(piwigo.PiwigoContext)
context.Piwigo.Url = fmt.Sprintf("%s/ws.php?format=json", *piwigoUrl) context.Piwigo.Url = fmt.Sprintf("%s/ws.php?format=json", *piwigoUrl)
@ -77,7 +77,7 @@ func configureContext() (*AppContext, error) {
return context, nil return context, nil
} }
func loginToPiwigoAndConfigureContext(context *AppContext) error { func loginToPiwigoAndConfigureContext(context *appContext) error {
logrus.Infoln("Logging in to piwigo and getting chunk size configuration for uploads") logrus.Infoln("Logging in to piwigo and getting chunk size configuration for uploads")
err := authentication.Login(context.Piwigo) err := authentication.Login(context.Piwigo)
if err != nil { if err != nil {
@ -86,7 +86,7 @@ func loginToPiwigoAndConfigureContext(context *AppContext) error {
return initializeUploadChunkSize(context) return initializeUploadChunkSize(context)
} }
func initializeUploadChunkSize(context *AppContext) error { func initializeUploadChunkSize(context *appContext) error {
userStatus, err := authentication.GetStatus(context.Piwigo) userStatus, err := authentication.GetStatus(context.Piwigo)
if err != nil { if err != nil {
return err return err

View File

@ -10,13 +10,13 @@ import (
"sort" "sort"
) )
func getAllCategoriesFromServer(context *AppContext) (map[string]*category.PiwigoCategory, error) { func getAllCategoriesFromServer(context *appContext) (map[string]*category.PiwigoCategory, error) {
logrus.Debugln("Starting GetAllCategories") logrus.Debugln("Starting GetAllCategories")
categories, err := category.GetAllCategories(context.Piwigo) categories, err := category.GetAllCategories(context.Piwigo)
return categories, err return categories, err
} }
func synchronizeCategories(context *AppContext, filesystemNodes map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error { func synchronizeCategories(context *appContext, filesystemNodes map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error {
logrus.Infoln("Synchronizing categories...") logrus.Infoln("Synchronizing categories...")
missingCategories := findMissingCategories(filesystemNodes, existingCategories) missingCategories := findMissingCategories(filesystemNodes, existingCategories)
@ -50,7 +50,7 @@ func findMissingCategories(fileSystem map[string]*localFileStructure.FilesystemN
return missingCategories return missingCategories
} }
func createMissingCategories(context *AppContext, missingCategories []string, existingCategories map[string]*category.PiwigoCategory) error { func createMissingCategories(context *appContext, missingCategories []string, existingCategories map[string]*category.PiwigoCategory) error {
// we sort them to make sure the categories gets created // we sort them to make sure the categories gets created
// 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)

View File

@ -7,7 +7,7 @@ import (
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/category" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/category"
) )
func synchronizeImages(context *AppContext, fileSystem map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error { func synchronizeImages(context *appContext, fileSystem map[string]*localFileStructure.FilesystemNode, existingCategories map[string]*category.PiwigoCategory) error {
imageFiles, err := localFileStructure.GetImageList(fileSystem) imageFiles, err := localFileStructure.GetImageList(fileSystem)
if err != nil { if err != nil {

View File

@ -4,7 +4,7 @@ import (
"haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo"
) )
type AppContext struct { type appContext struct {
Piwigo *piwigo.PiwigoContext Piwigo *piwigo.PiwigoContext
SessionId string SessionId string
LocalRootPath string LocalRootPath string