(app *App, u *url.URL)
| 1153 | } |
| 1154 | |
| 1155 | func parsePostIDFromURL(app *App, u *url.URL) (string, error) { |
| 1156 | // Get post ID from URL |
| 1157 | var collAlias, slug, postID string |
| 1158 | if m := apCollectionPostIRIRegex.FindStringSubmatch(u.String()); len(m) == 3 { |
| 1159 | collAlias = m[1] |
| 1160 | slug = m[2] |
| 1161 | } else if m = apDraftPostIRIRegex.FindStringSubmatch(u.String()); len(m) == 2 { |
| 1162 | postID = m[1] |
| 1163 | } else { |
| 1164 | return "", fmt.Errorf("unable to match objectIRI: %s", u) |
| 1165 | } |
| 1166 | |
| 1167 | // Get postID if all we have is collection and slug |
| 1168 | if collAlias != "" && slug != "" { |
| 1169 | c, err := app.db.GetCollection(collAlias) |
| 1170 | if err != nil { |
| 1171 | return "", err |
| 1172 | } |
| 1173 | p, err := app.db.GetPost(slug, c.ID) |
| 1174 | if err != nil { |
| 1175 | return "", err |
| 1176 | } |
| 1177 | postID = p.ID |
| 1178 | } |
| 1179 | |
| 1180 | return postID, nil |
| 1181 | } |
| 1182 | |
| 1183 | func setCacheControl(w http.ResponseWriter, ttl time.Duration) { |
| 1184 | w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%.0f", ttl.Seconds())) |
no test coverage detected