summaryrefslogtreecommitdiff
path: root/cmd/rescribe/gbook.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/rescribe/gbook.go')
-rw-r--r--cmd/rescribe/gbook.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/cmd/rescribe/gbook.go b/cmd/rescribe/gbook.go
index fe2f4b8..a011181 100644
--- a/cmd/rescribe/gbook.go
+++ b/cmd/rescribe/gbook.go
@@ -41,7 +41,9 @@ func formatAuthors(authors []string) string {
s = strings.ToUpper(s)
if len(s) > maxPartLength {
- s = s[:maxPartLength]
+ // truncate to maxPartLength
+ m := fmt.Sprintf("%%.%ds", maxPartLength)
+ s = fmt.Sprintf(m, s)
}
s = strings.Map(stripNonLetters, s)
@@ -63,7 +65,9 @@ func stripNonLetters(r rune) rune {
func formatTitle(title string) string {
s := strings.Map(stripNonLetters, title)
if len(s) > maxPartLength {
- s = s[:maxPartLength]
+ // truncate to maxPartLength
+ m := fmt.Sprintf("%%.%ds", maxPartLength)
+ s = fmt.Sprintf(m, s)
}
return s
}
@@ -77,8 +81,8 @@ func getMetadata(id string) (string, string, string, error) {
// designed to be unmarshalled by encoding/json's Unmarshal()
type bookInfo struct {
VolumeInfo struct {
- Title string
- Authors []string
+ Title string
+ Authors []string
PublishedDate string
}
}
@@ -232,7 +236,7 @@ func getBookIdFromUrl(url string) (string, error) {
if start >= 0 {
start += 4
- if len(url[start:]) < 12 {
+ if len(url) - start < 12 {
return "", fmt.Errorf("Could not find book ID in URL")
}
return url[start : start+12], nil
@@ -245,7 +249,7 @@ func getBookIdFromUrl(url string) (string, error) {
if start >= 0 {
start += 10
- if len(url[start:]) < 12 {
+ if len(url) - start < 12 {
return "", fmt.Errorf("Could not find book ID in URL")
}
return url[start : start+12], nil