package router

import (
	"html/template"
	"net/http"

	"github.com/gorilla/mux"
)

var notFoundTemplate = template.Must(template.New("NotFound").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/404.html"))

func init() {
	// common
	template.Must(notFoundTemplate.ParseGlob("templates/_*.html"))
}

func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
	searchForm := NewSearchForm()
	searchForm.HideAdvancedSearch = true
	err := notFoundTemplate.ExecuteTemplate(w, "index.html", NotFoundTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}

package router

import (
	"html/template"
	"net/http"

	"github.com/gorilla/mux"
)

var notFoundTemplate = template.Must(template.New("NotFound").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/404.html"))

func init() {
	// common
	template.Must(notFoundTemplate.ParseGlob("templates/_*.html"))
}

func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusNotFound)

	searchForm := NewSearchForm()
	searchForm.HideAdvancedSearch = true
	err := notFoundTemplate.ExecuteTemplate(w, "index.html", NotFoundTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}

Return status code 404 on 404 page
Return status code 404 on 404 page

The NotFoundHandler previously returned status code 200
because WriteHeader wasn't called.
