Moved away from local files to complete database driven articles
This commit is contained in:
@@ -2,33 +2,28 @@ package server
|
||||
|
||||
import (
|
||||
"TheAdversary/database"
|
||||
"TheAdversary/parse"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// var tmpl = template.Must(template.ParseFiles(config.ArticleTemplate))
|
||||
|
||||
func Article(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
articleName := mux.Vars(r)["article"]
|
||||
|
||||
article, err := database.GetDB().GetArticleByName(articleName)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
Error404(w, r)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
Error500(w, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
parsed, _ := parse.ParseToHtml(article)
|
||||
if len(parsed) > 0 {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, string(parsed))
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, article.Html)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user