From 82a53c3c5b5ffd8af9c69c6184134f100f80b89a Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 14 Mar 2020 13:54:35 +0530 Subject: Unexport GetPathFromID & further break it in 2 functions appendSizeToPath will get repeated later so seperated it into a different function --- pkg/unsplash/unsplash.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/unsplash/unsplash.go b/pkg/unsplash/unsplash.go index 689f8c4..a284ebc 100644 --- a/pkg/unsplash/unsplash.go +++ b/pkg/unsplash/unsplash.go @@ -20,23 +20,27 @@ import ( "framagit.org/andinus/cetus/pkg" ) -// 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) + path = getPathFromID(photoID) + path = appendSizeToPath(path, width, height) err = background.Set(path) - return err } + +func getPathFromID(photoID string) string { + var path string + path = fmt.Sprintf("%s/%s", "https://source.unsplash.com", photoID) + return path +} + +func appendSizeToPath(path string, width int, height int) string { + var size string + + size = fmt.Sprintf("%dx%d", width, height) + path = fmt.Sprintf("%s/%s", path, size) + return path +} -- cgit 1.4.1-2-gfad0