func AuthMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := context.Get(req) articleName := ctx.Params.ByName("article") if strings.Contains(articleName, "secret") { w.WriteHeader(403) fmt.Fprint(w, "Sorry, this is security site") return } next.ServeHTTP(w, req) }) }
func ShowArticle(w http.ResponseWriter, r *http.Request) { ctx := context.Get(r) databasePath := "src/GoDay5/database" + "/" + ctx.Params.ByName("article") // Test connect database session := rethinkdb.Connect() rethinkdb.CreateTable(session) html, err := loadMarkdown.FromFile(databasePath) if err != nil { w.WriteHeader(404) fmt.Fprint(w, "Not found") fmt.Println(err) } w.Header().Add("Content-Type", "text/html") w.WriteHeader(200) w.Write(html) }