diff --git a/pkg/repo/api.go b/pkg/repo/api.go index e7bd963..2468bc4 100644 --- a/pkg/repo/api.go +++ b/pkg/repo/api.go @@ -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 @@ -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() diff --git a/pkg/static/template_funcs.go b/pkg/static/template_funcs.go index 32d47ef..89d9465 100644 --- a/pkg/static/template_funcs.go +++ b/pkg/static/template_funcs.go @@ -43,7 +43,11 @@ func GetPostPath(post types.Post) string { // GetPostExcerpt is a template function func GetPostExcerpt(content string) string { - return strings.Split(content, "")[0] + split := strings.Split(content, "") + if len(split) > 0 { + return split[0] + } + return "" } // GetLikePath is a template function