Skip to content

Commit

Permalink
Attempt to fix potential nil issues
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemblack committed Nov 19, 2023
1 parent 38c4874 commit 8e04657
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/repo/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewAPIService(config conf.Config) (APIService, error) {
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return APIService{}, types.WrapErr(err, "invalid status code from api")
}
if resp.Body == nil {
return APIService{}, types.WrapErr(err, "empty response body")
}

defer resp.Body.Close()

var authTokenResponse AuthTokenResponse
Expand Down Expand Up @@ -84,6 +88,9 @@ func (api *APIService) GetPublishedPosts() (types.Posts, error) {
}

// URL params and headers
if req.URL == nil {
return types.Posts{}, types.WrapErr(err, "empty http request url")
}
query := req.URL.Query()
query.Add("published", "true")
req.URL.RawQuery = query.Encode()
Expand Down
6 changes: 5 additions & 1 deletion pkg/static/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func GetPostPath(post types.Post) string {

// GetPostExcerpt is a template function
func GetPostExcerpt(content string) string {
return strings.Split(content, "<!--more-->")[0]
split := strings.Split(content, "<!--more-->")
if len(split) > 0 {
return split[0]
}
return ""
}

// GetLikePath is a template function
Expand Down

0 comments on commit 8e04657

Please sign in to comment.