package render import ( "fmt" "log/slog" "net/http" "strings" settings "physick.ru/Settings" ) type IndexTemplateContents struct { LastArticles []recentArticle Content string } type recentArticle struct { Link string DisplayName string } func RegisterEndpoints() { // http.Handle("static/", http.FileServer(http.FS(os.DirFS(settings.Current.StaticLocation)))) http.HandleFunc("/articles/{name}", test) http.HandleFunc("/", mux) } func mux(w http.ResponseWriter, r *http.Request) { // slog.Info("Request", slog.String("URL", r.URL.String())) if r.URL.String() == "/favicon.ico" { http.ServeFile(w, r, fmt.Sprintf("%s/favicon.ico", settings.Current.StaticLocation)) } if strings.HasPrefix(r.URL.String(), "/static") { var filePath = strings.Replace(r.URL.String(), "/static", settings.Current.StaticLocation, 1) http.ServeFile(w, r, filePath) return } common(w, r) } func common(w http.ResponseWriter, r *http.Request) { var indexArticle, indexErr = getTemplate("index.html") if indexErr != nil { slog.Error("Failed to parse the template", slog.Any("Error", indexErr)) w.WriteHeader(http.StatusInternalServerError) return } executeIndexTemplate(IndexTemplateContents{ LastArticles: []recentArticle { recentArticle { Link: "/", DisplayName: "Index page", }, }, Content: indexArticle, }, w) } func test(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "xdx") }