Files
backend/server/article.go

30 lines
623 B
Go

package server
import (
"TheAdversary/database"
"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"]
var article string
if err := database.GetDB().Table("article").Select("html").Where("name = ?", articleName).First(&article).Error; err != nil {
if err == sql.ErrNoRows {
Error404(w, r)
} else {
Error500(w, r)
}
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, article)
}