From 6ccfe4931a3e71c2f22fc04ce0efb9a9f554abdd Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 14 Mar 2020 13:40:03 +0530 Subject: Break SetFromID in 2 functions GetPathFromID returns the path of the photo & SetFromID first gets the path from GetPathFromID then uses background.Set to set the background --- pkg/unsplash/unsplash.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/unsplash/unsplash.go b/pkg/unsplash/unsplash.go index e40503d..689f8c4 100644 --- a/pkg/unsplash/unsplash.go +++ b/pkg/unsplash/unsplash.go @@ -20,17 +20,22 @@ import ( "framagit.org/andinus/cetus/pkg" ) -// SetFromID sets background from Unsplash Photo ID -func SetFromID(photoID string, width int, height int) error { - var ( - path string - size string - - err error - ) +// GetPathFromID returns path of the photo from Unsplash Photo ID +func GetPathFromID(photoID string, width int, height int) string { + var path string + var size string size = fmt.Sprintf("%dx%d", width, height) path = fmt.Sprintf("%s/%s/%s", "https://source.unsplash.com", photoID, size) + return path +} + +// SetFromID sets background from Unsplash Photo ID +func SetFromID(photoID string, width int, height int) error { + var path string + var err error + + path = GetPathFromID(photoID, width, height) err = background.Set(path) return err -- cgit 1.4.1-2-gfad0