35 lines
679 B
Go
35 lines
679 B
Go
package server
|
|
|
|
import (
|
|
"TheAdversary/database"
|
|
"TheAdversary/parse"
|
|
"database/sql"
|
|
"fmt"
|
|
"github.com/gorilla/mux"
|
|
"net/http"
|
|
)
|
|
|
|
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)
|
|
} else {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
return
|
|
}
|
|
|
|
parsed, _ := parse.ParseToHtml(article)
|
|
if len(parsed) > 0 {
|
|
w.WriteHeader(http.StatusOK)
|
|
fmt.Fprint(w, string(parsed))
|
|
} else {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}
|
|
}
|