"html"
"io"
"log"
+ "net/http"
"net/url"
"os"
"strconv"
return strings.Join(lines, "\n")
}
-func makeErr(err error) {
+func makeErr(err error, status int) {
+ fmt.Println("Status:", status)
fmt.Print("Content-Type: text/plain; charset=UTF-8\n\n")
fmt.Println(err)
log.Fatalln(err)
}
queryValues, err := url.ParseQuery(os.Getenv("QUERY_STRING"))
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusBadRequest)
}
etagHash, err := blake2b.New256(nil)
headHash, err := initRepo(cfg)
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
if notes, err := repo.Notes(); err == nil {
if offsetRaw, exists := queryValues["offset"]; exists {
offset, err = strconv.Atoi(offsetRaw[0])
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusBadRequest)
}
}
repoLog, err := repo.Log(&git.LogOptions{From: *headHash})
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
topicsCache, err := getTopicsCache(cfg, repoLog)
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
repoLog, err = repo.Log(&git.LogOptions{From: *headHash})
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
commitN := 0
topic = t[0]
hashes := topicsCache[topic]
if hashes == nil {
- makeErr(errors.New("no posts with that topic"))
+ makeErr(errors.New("no posts with that topic"), http.StatusBadRequest)
}
if len(hashes) > offset {
hashes = hashes[offset:]
Entries: entries,
})
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
} else if pathInfo == "/"+AtomPostsFeed {
commit, err := repo.CommitObject(*headHash)
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
var topic string
repoLog, err := repo.Log(&git.LogOptions{From: *headHash})
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
var commits CommitIterNext
if topic == "" {
} else {
topicsCache, err := getTopicsCache(cfg, repoLog)
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
hashes := topicsCache[topic]
if hashes == nil {
- makeErr(errors.New("no posts with that topic"))
+ makeErr(errors.New("no posts with that topic"), http.StatusBadRequest)
}
commits = &HashesIter{hashes}
}
}
data, err := xml.MarshalIndent(&feed, "", " ")
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
out.Write(data)
goto AtomFinish
} else if pathInfo == "/"+AtomCommentsFeed {
commit, err := repo.CommitObject(commentsRef.Hash())
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
etagHash.Write([]byte("ATOM COMMENTS"))
etagHash.Write(commit.Hash[:])
}
repoLog, err := repo.Log(&git.LogOptions{From: commentsRef.Hash()})
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
for i := 0; i < PageEntries; i++ {
commit, err = repoLog.Next()
}
fileStats, err := commit.Stats()
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
t, err := commit.Tree()
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
commentedHash := plumbing.NewHash(strings.ReplaceAll(
fileStats[0].Name, "/", "",
}
data, err := xml.MarshalIndent(&feed, "", " ")
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
out.Write(data)
goto AtomFinish
} else if sha1DigestRe.MatchString(pathInfo[1:]) {
commit, err := repo.CommitObject(plumbing.NewHash(pathInfo[1 : 1+sha1.Size*2]))
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusBadRequest)
}
for _, data := range etagHashForWeb {
etagHash.Write([]byte(data))
}
data, err := xml.MarshalIndent(&feed, "", " ")
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
out.Write(data)
goto AtomFinish
Topics: sgblog.ParseTopics(topicsRaw),
})
if err != nil {
- makeErr(err)
+ makeErr(err, http.StatusInternalServerError)
}
} else {
- makeErr(errors.New("unknown URL action"))
+ makeErr(errors.New("unknown URL action"), http.StatusNotFound)
}
out.Write([]byte("</body></html>\n"))
if gzipWriter != nil {