src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

page.go (500B)


      1 package site
      2 
      3 import (
      4 	"fmt"
      5 	"net/http"
      6 )
      7 
      8 func (s *Site) page(w http.ResponseWriter, r *http.Request) {
      9 	if r.Method != http.MethodGet {
     10 		w.WriteHeader(http.StatusMethodNotAllowed)
     11 		return
     12 	}
     13 
     14 	if page := s.pages[r.URL.Path]; page != nil {
     15 		w.WriteHeader(http.StatusOK)
     16 		w.Write(page.Bytes())
     17 		return
     18 	}
     19 
     20 	s.error(w, r, &Error{
     21 		Code:  http.StatusNotFound,
     22 		Error: fmt.Errorf("no page for %s", r.URL.Path),
     23 		Message: fmt.Sprintf(
     24 			"Sorry, but %s does not exist.", r.URL.Path,
     25 		),
     26 	})
     27 }