Fix slice out of bounds error

Fixes following error:

  panic: runtime error: slice bounds out of range [:80] with length 53
This commit is contained in:
ekzyis 2023-08-31 09:56:51 +02:00
parent bd4c8fb4a9
commit c7e368ed2e
1 changed files with 6 additions and 1 deletions

7
sn.go
View File

@ -38,7 +38,12 @@ func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error)
} }
} }
parentId, err := sn.PostLink(url, story.Title[0:80], "tech") title := story.Title
if len(title) > 80 {
title = title[0:80]
}
parentId, err := sn.PostLink(url, title, "tech")
if err != nil { if err != nil {
return -1, fmt.Errorf("error posting link: %w", err) return -1, fmt.Errorf("error posting link: %w", err)
} }