Initial release
This commit is contained in:
34
server/article.go
Normal file
34
server/article.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user