- test(ui): avoid a literal em dash in the em dash check - fix(cli): accept any positive int64 audit count and share the last active admin rule - fix(api): limit audit before_id to 2^53-1 - fix(api): audit unmatched api requests, bound every request body and record audit write failures - fix(ui): recheck the account in the login transaction and require existing zones on zone pages - fix(api): recheck the acting admin and the stored password hash in change transactions - fix(db): keep committed outcomes on lock release failure, narrow the records contract and trace sql statements - fix(db): make the initial migration restartable and verify the application schema - fix(auth): never move last_seen_at backwards on concurrent session touches - test(api): cover lock release failure after commit and handler tracing without secrets - fix(test): redact credentials from mysql setup errors - fix(audit): retain addressed objects on admin refusals - test(db): cover migration restarts and records contract ranges in mysql - test(api): verify account races and audit rollback in mysql - fix(auth): reject password changes after account deletion - docs: document unknown api audit entries - fix(audit): bound failure retries and redact sensitive sql parameters - fix(test): isolate docker resources and cover image cli commands - test(auth): expect unauthorized after an account deletion race - fix(db): verify application column widths and foreign keys
581 lines
17 KiB
Go
581 lines
17 KiB
Go
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/sha256"
|
|
"embed"
|
|
"encoding/hex"
|
|
"errors"
|
|
"fmt"
|
|
"html/template"
|
|
"io/fs"
|
|
"maps"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"slices"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
//go:embed templates/html
|
|
var uiTemplateFiles embed.FS
|
|
|
|
//go:embed static
|
|
var uiStaticFiles embed.FS
|
|
|
|
const defaultBootstrapCommand = "docker exec -i <container> /app user add <username> admin"
|
|
|
|
var uiContentTypes = map[string]string{
|
|
".css": "text/css; charset=utf-8",
|
|
".js": "text/javascript; charset=utf-8",
|
|
".mjs": "text/javascript; charset=utf-8",
|
|
".svg": "image/svg+xml",
|
|
".json": "application/json",
|
|
".txt": "text/plain; charset=utf-8",
|
|
".ico": "image/x-icon",
|
|
".png": "image/png",
|
|
".woff2": "font/woff2",
|
|
}
|
|
|
|
type pageData struct {
|
|
AppName string
|
|
Static string
|
|
Page string
|
|
Script string
|
|
Username string
|
|
Role string
|
|
Zone string
|
|
TargetUser string
|
|
Next string
|
|
Error string
|
|
NoActiveAdmin bool
|
|
BootstrapCommand string
|
|
}
|
|
|
|
func (d pageData) IsAdmin() bool {
|
|
return d.Role == "admin"
|
|
}
|
|
|
|
func (d pageData) Section() string {
|
|
switch d.Page {
|
|
case "zones", "zone", "import":
|
|
return "zones"
|
|
case "users", "user":
|
|
return "users"
|
|
}
|
|
return d.Page
|
|
}
|
|
|
|
type pageRenderer struct {
|
|
templates map[string]*template.Template
|
|
static fs.FS
|
|
hash string
|
|
prefix string
|
|
}
|
|
|
|
func staticHash(fsys fs.FS) (string, error) {
|
|
sum := sha256.New()
|
|
err := fs.WalkDir(fsys, ".", func(name string, entry fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if entry.IsDir() {
|
|
return nil
|
|
}
|
|
data, err := fs.ReadFile(fsys, name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(sum, "%s\x00%d\x00", name, len(data))
|
|
sum.Write(data)
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return hex.EncodeToString(sum.Sum(nil))[:16], nil
|
|
}
|
|
|
|
func newPageRenderer() (*pageRenderer, error) {
|
|
templates, err := fs.Sub(uiTemplateFiles, "templates/html")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
static, err := fs.Sub(uiStaticFiles, "static")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return newPageRendererFS(templates, static)
|
|
}
|
|
|
|
func newPageRendererFS(templates, static fs.FS) (*pageRenderer, error) {
|
|
hash, err := staticHash(static)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("hash static files: %w", err)
|
|
}
|
|
pages, err := fs.Glob(templates, "pages/*.html")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(pages) == 0 {
|
|
return nil, fmt.Errorf("no page templates found")
|
|
}
|
|
renderer := &pageRenderer{
|
|
templates: make(map[string]*template.Template, len(pages)),
|
|
static: static,
|
|
hash: hash,
|
|
prefix: "/static/" + hash + "/",
|
|
}
|
|
for _, file := range pages {
|
|
name := strings.TrimSuffix(path.Base(file), ".html")
|
|
tmpl, err := template.New(name).ParseFS(templates, "layout.html", "partials/*.html", file)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse page %s: %w", name, err)
|
|
}
|
|
renderer.templates[name] = tmpl
|
|
}
|
|
return renderer, nil
|
|
}
|
|
|
|
func (p *pageRenderer) staticPrefix() string {
|
|
return p.prefix
|
|
}
|
|
|
|
func (p *pageRenderer) hasScript(page string) bool {
|
|
info, err := fs.Stat(p.static, "js/"+page+".js")
|
|
return err == nil && !info.IsDir()
|
|
}
|
|
|
|
func (p *pageRenderer) render(w http.ResponseWriter, status int, page string, data pageData) {
|
|
tmpl, ok := p.templates[page]
|
|
if !ok {
|
|
http.Error(w, "internal server error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
data.Static = p.prefix
|
|
data.Page = page
|
|
if p.hasScript(page) {
|
|
data.Script = page
|
|
}
|
|
if data.NoActiveAdmin && data.BootstrapCommand == "" {
|
|
data.BootstrapCommand = defaultBootstrapCommand
|
|
}
|
|
var buf bytes.Buffer
|
|
if err := tmpl.ExecuteTemplate(&buf, "layout", data); err != nil {
|
|
http.Error(w, "internal server error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
w.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
|
|
w.WriteHeader(status)
|
|
w.Write(buf.Bytes())
|
|
}
|
|
|
|
func (p *pageRenderer) staticHandler() http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
|
w.Header().Set("Allow", "GET, HEAD")
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
if !strings.HasPrefix(r.URL.Path, p.prefix) {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
name := strings.TrimPrefix(r.URL.Path, p.prefix)
|
|
if name == "" || strings.ContainsAny(name, "\\\x00") || !fs.ValidPath(name) {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
data, err := fs.ReadFile(p.static, name)
|
|
if err != nil {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
contentType, ok := uiContentTypes[strings.ToLower(path.Ext(name))]
|
|
if !ok {
|
|
contentType = "application/octet-stream"
|
|
}
|
|
w.Header().Set("Content-Type", contentType)
|
|
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
|
w.WriteHeader(http.StatusOK)
|
|
if r.Method == http.MethodGet {
|
|
w.Write(data)
|
|
}
|
|
})
|
|
}
|
|
|
|
const (
|
|
loginFormLimit = 64 << 10
|
|
msgInvalidLogin = "invalid username or password"
|
|
msgTooManyLogins = "too many failed login attempts, try again later"
|
|
msgLoginUnavailable = "login is temporarily unavailable, try again later"
|
|
msgInvalidLoginForm = "the login form is invalid"
|
|
msgPageUnavailable = "service unavailable"
|
|
msgPageInternalError = "internal server error"
|
|
)
|
|
|
|
func validNextPath(next string) bool {
|
|
if !strings.HasPrefix(next, "/") || strings.HasPrefix(next, "//") || strings.ContainsAny(next, "\\") {
|
|
return false
|
|
}
|
|
for _, r := range next {
|
|
if r < 0x20 || r == 0x7f {
|
|
return false
|
|
}
|
|
}
|
|
u, err := url.Parse(next)
|
|
return err == nil && u.Scheme == "" && u.Host == "" && u.User == nil
|
|
}
|
|
|
|
func safeNext(next string) string {
|
|
if validNextPath(next) {
|
|
return next
|
|
}
|
|
return "/"
|
|
}
|
|
|
|
func loginLocation(r *http.Request) string {
|
|
return "/login?next=" + url.QueryEscape(r.URL.RequestURI())
|
|
}
|
|
|
|
func (s *WebServer) basePageData() pageData {
|
|
return pageData{AppName: s.cfg.AppName}
|
|
}
|
|
|
|
func sessionPageData(base pageData, p principal) pageData {
|
|
base.Username, base.Role = p.User.Username, p.User.Role
|
|
return base
|
|
}
|
|
|
|
func (s *WebServer) renderPage(w http.ResponseWriter, status int, page string, data pageData) {
|
|
if s.pages == nil {
|
|
http.Error(w, msgPageInternalError, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
s.pages.render(w, status, page, data)
|
|
}
|
|
|
|
func (s *WebServer) pageFailure(w http.ResponseWriter, r *http.Request, err error) {
|
|
s.log.ErrorContext(r.Context(), "page request failed", "path", r.URL.Path, "error", err)
|
|
status, _ := failureStatus(err)
|
|
pageError(w, status)
|
|
}
|
|
|
|
func pageError(w http.ResponseWriter, status int) {
|
|
if status == http.StatusServiceUnavailable {
|
|
http.Error(w, msgPageUnavailable, status)
|
|
return
|
|
}
|
|
http.Error(w, msgPageInternalError, http.StatusInternalServerError)
|
|
}
|
|
|
|
func (s *WebServer) pageZoneExists(ctx context.Context, zone string) (bool, error) {
|
|
for _, stored := range []string{zone, strings.TrimSuffix(zone, ".")} {
|
|
ok, err := s.store.ZoneExists(ctx, stored)
|
|
if err != nil || ok {
|
|
return ok, err
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|
|
|
|
func (s *WebServer) optionalPageData(r *http.Request) pageData {
|
|
data := s.basePageData()
|
|
if p, err := s.authenticate(r); err == nil {
|
|
data = sessionPageData(data, p)
|
|
}
|
|
return data
|
|
}
|
|
|
|
func (s *WebServer) handleNotFoundPage(w http.ResponseWriter, r *http.Request) {
|
|
s.renderPage(w, http.StatusNotFound, "not_found", s.optionalPageData(r))
|
|
}
|
|
|
|
func (s *WebServer) handleMethodNotAllowed(allow string) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Allow", allow)
|
|
http.Error(w, msgMethodNotAllowed, http.StatusMethodNotAllowed)
|
|
}
|
|
}
|
|
|
|
func (s *WebServer) servePage(route pageRoute) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
defer traceFunc(ctx, s.log, "page."+route.Page)()
|
|
p, err := s.authenticate(r)
|
|
if errors.Is(err, errNoSession) {
|
|
http.Redirect(w, r, loginLocation(r), http.StatusSeeOther)
|
|
return
|
|
}
|
|
if err != nil {
|
|
s.pageFailure(w, r, err)
|
|
return
|
|
}
|
|
data := sessionPageData(s.basePageData(), p)
|
|
if authorize(route.Access, &p, true) == accessForbidden {
|
|
s.log.WarnContext(ctx, "admin page refused", "path", r.URL.Path, "user", p.User.Username)
|
|
s.renderPage(w, http.StatusForbidden, "forbidden", data)
|
|
return
|
|
}
|
|
vars := mux.Vars(r)
|
|
if username, ok := vars["username"]; ok {
|
|
if !validUsernameSyntax(username) {
|
|
s.renderPage(w, http.StatusNotFound, "not_found", data)
|
|
return
|
|
}
|
|
data.TargetUser = username
|
|
}
|
|
if routeHasZone(route.Path) {
|
|
zone, err := normalizeZone(vars["zone"])
|
|
if err != nil {
|
|
s.renderPage(w, http.StatusNotFound, "not_found", data)
|
|
return
|
|
}
|
|
delegated := false
|
|
if needsDelegation(route.Access, p) {
|
|
if delegated, err = s.store.HasDelegation(ctx, zone, p.User.ID); err != nil {
|
|
s.pageFailure(w, r, err)
|
|
return
|
|
}
|
|
}
|
|
if authorize(route.Access, &p, delegated) == accessNotFound {
|
|
s.log.WarnContext(ctx, "zone not delegated", "path", r.URL.Path, "zone", zone, "user", p.User.Username)
|
|
s.renderPage(w, http.StatusNotFound, "not_found", data)
|
|
return
|
|
}
|
|
exists, err := s.pageZoneExists(ctx, zone)
|
|
if err != nil {
|
|
s.pageFailure(w, r, err)
|
|
return
|
|
}
|
|
if !exists {
|
|
s.renderPage(w, http.StatusNotFound, "not_found", data)
|
|
return
|
|
}
|
|
data.Zone = zone
|
|
}
|
|
s.renderPage(w, http.StatusOK, route.Page, data)
|
|
}
|
|
}
|
|
|
|
func (s *WebServer) renderLogin(w http.ResponseWriter, r *http.Request, status int, next, message string) {
|
|
data := s.basePageData()
|
|
data.Next = safeNext(next)
|
|
data.Error = message
|
|
if s.store != nil {
|
|
hasAdmin, err := s.store.HasActiveAdmin(r.Context())
|
|
if err != nil {
|
|
s.log.ErrorContext(r.Context(), "active admin lookup failed", "error", err)
|
|
}
|
|
data.NoActiveAdmin = err == nil && !hasAdmin
|
|
}
|
|
s.renderPage(w, status, "login", data)
|
|
}
|
|
|
|
func (s *WebServer) handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
|
defer traceFunc(r.Context(), s.log, "page.login.get")()
|
|
s.renderLogin(w, r, http.StatusOK, r.URL.Query().Get("next"), "")
|
|
}
|
|
|
|
var errLoginStale = errors.New("account changed during login")
|
|
|
|
func (s *WebServer) loginAttemptAudit(ctx context.Context, e auditEntry, status int, message string) int {
|
|
finishAuditEntry(&e, status, message)
|
|
if !s.recordAudit(ctx, e) {
|
|
return http.StatusInternalServerError
|
|
}
|
|
return status
|
|
}
|
|
|
|
func (s *WebServer) sessionOperationFailure(ctx context.Context, e auditEntry, err error) int {
|
|
if isAuditWriteError(err) {
|
|
s.recordInternalAudit(ctx, e)
|
|
return http.StatusInternalServerError
|
|
}
|
|
status, msg := failureStatus(err)
|
|
return s.loginAttemptAudit(ctx, e, status, msg)
|
|
}
|
|
|
|
func (s *WebServer) handleLogin(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
defer traceFunc(ctx, s.log, "page.login.post")()
|
|
r.Body = http.MaxBytesReader(w, r.Body, loginFormLimit)
|
|
if err := r.ParseForm(); err != nil {
|
|
s.log.DebugContext(ctx, "invalid login form", "error", err)
|
|
s.renderLogin(w, r, http.StatusBadRequest, "", msgInvalidLoginForm)
|
|
return
|
|
}
|
|
username, password, next := r.PostForm.Get("username"), r.PostForm.Get("password"), safeNext(r.PostForm.Get("next"))
|
|
origin := clientOrigin(r, s.cfg.TrustedProxies)
|
|
actor := loginActor(username)
|
|
now := s.now().UTC()
|
|
if s.store == nil {
|
|
s.pageFailure(w, r, errDatabase)
|
|
return
|
|
}
|
|
var user *userRow
|
|
if validUsernameSyntax(username) {
|
|
u, err := s.store.UserByUsername(ctx, username)
|
|
switch {
|
|
case err == nil:
|
|
user = &u
|
|
case !errors.Is(err, errRowNotFound):
|
|
s.log.ErrorContext(ctx, "login user lookup failed", "error", err)
|
|
status, msg := failureStatus(err)
|
|
status = s.loginAttemptAudit(ctx, loginAuditEntry(now, opLogin, username, nil, origin), status, msg)
|
|
s.renderLogin(w, r, status, next, msgLoginUnavailable)
|
|
return
|
|
}
|
|
}
|
|
entry := loginAuditEntry(now, opLogin, username, user, origin)
|
|
if !s.limiter.allow(actor, origin) {
|
|
s.log.WarnContext(ctx, "login rate limited", "actor", actor, "origin", origin)
|
|
s.renderLoginResult(w, r, s.loginAttemptAudit(ctx, entry, http.StatusTooManyRequests, msgTooManyLogins), next, msgTooManyLogins)
|
|
return
|
|
}
|
|
if !verifyLogin(s.verifyPassword, user, password) {
|
|
s.limiter.fail(actor, origin)
|
|
s.log.WarnContext(ctx, "login failed", "actor", actor, "origin", origin)
|
|
s.renderLoginResult(w, r, s.loginAttemptAudit(ctx, entry, http.StatusUnauthorized, msgInvalidLogin), next, msgInvalidLogin)
|
|
return
|
|
}
|
|
token, hash, err := newSessionToken(s.random)
|
|
if err == nil {
|
|
err = s.store.InTx(ctx, func(tx webTx) error {
|
|
current, err := tx.UserByIDForUpdate(ctx, user.ID)
|
|
if errors.Is(err, errRowNotFound) {
|
|
return errLoginStale
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if current.DeletedAt.Valid || current.PasswordHash != user.PasswordHash {
|
|
return errLoginStale
|
|
}
|
|
if old, ok := requestSessionToken(r); ok {
|
|
if _, err := tx.DeleteSession(ctx, sessionTokenHash(old)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if err := tx.CreateSession(ctx, newSessionRow(hash, user.ID, now, s.cfg.SessionMaxAge, origin, r.UserAgent())); err != nil {
|
|
return err
|
|
}
|
|
if err := tx.TouchLastLogin(ctx, user.ID, now); err != nil {
|
|
return err
|
|
}
|
|
e := entry
|
|
finishAuditEntry(&e, http.StatusSeeOther, "")
|
|
return insertAuditRow(ctx, tx, e)
|
|
})
|
|
}
|
|
if errors.Is(err, errLoginStale) {
|
|
s.limiter.fail(actor, origin)
|
|
s.log.WarnContext(ctx, "login failed", "actor", actor, "origin", origin, "reason", "account changed during login")
|
|
s.renderLoginResult(w, r, s.loginAttemptAudit(ctx, entry, http.StatusUnauthorized, msgInvalidLogin), next, msgInvalidLogin)
|
|
return
|
|
}
|
|
if err != nil {
|
|
s.log.ErrorContext(ctx, "login failed with an internal error", "actor", actor, "error", err)
|
|
s.renderLogin(w, r, s.sessionOperationFailure(ctx, entry, err), next, msgLoginUnavailable)
|
|
return
|
|
}
|
|
s.limiter.succeed(actor)
|
|
s.log.InfoContext(ctx, "change committed", "operation", opLogin, "actor", user.Username)
|
|
setRequestUser(r, principal{User: *user})
|
|
http.SetCookie(w, sessionCookie(token, s.cfg.CookieSecure))
|
|
http.Redirect(w, r, next, http.StatusSeeOther)
|
|
}
|
|
|
|
func (s *WebServer) renderLoginResult(w http.ResponseWriter, r *http.Request, status int, next, message string) {
|
|
if status == http.StatusInternalServerError {
|
|
message = msgLoginUnavailable
|
|
}
|
|
s.renderLogin(w, r, status, next, message)
|
|
}
|
|
|
|
func (s *WebServer) handleLogout(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
defer traceFunc(ctx, s.log, "page.logout")()
|
|
p, err := s.authenticate(r)
|
|
if errors.Is(err, errNoSession) {
|
|
http.SetCookie(w, expiredSessionCookie(s.cfg.CookieSecure))
|
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
|
return
|
|
}
|
|
if err != nil {
|
|
s.pageFailure(w, r, err)
|
|
return
|
|
}
|
|
entry := apiAuditEntry(s.now().UTC(), p, clientOrigin(r, s.cfg.TrustedProxies), opLogout, "")
|
|
err = s.store.InTx(ctx, func(tx webTx) error {
|
|
if _, err := tx.DeleteSession(ctx, p.TokenHash); err != nil {
|
|
return err
|
|
}
|
|
e := entry
|
|
finishAuditEntry(&e, http.StatusSeeOther, "")
|
|
return insertAuditRow(ctx, tx, e)
|
|
})
|
|
if err != nil {
|
|
s.log.ErrorContext(ctx, "logout failed", "error", err)
|
|
pageError(w, s.sessionOperationFailure(ctx, entry, err))
|
|
return
|
|
}
|
|
s.log.InfoContext(ctx, "change committed", "operation", opLogout, "actor", p.User.Username)
|
|
http.SetCookie(w, expiredSessionCookie(s.cfg.CookieSecure))
|
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
|
}
|
|
|
|
func (s *WebServer) registerPageRoutes(r *mux.Router) {
|
|
special := map[string]http.HandlerFunc{
|
|
"GET /login": s.handleLoginPage,
|
|
"POST /login": s.handleLogin,
|
|
"POST /logout": s.handleLogout,
|
|
}
|
|
if s.pages != nil {
|
|
static := s.pages.staticHandler()
|
|
r.PathPrefix("/static/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
defer traceFunc(req.Context(), s.log, "page.static")()
|
|
static.ServeHTTP(w, req)
|
|
})
|
|
}
|
|
byPath := map[string]map[string]http.HandlerFunc{}
|
|
var paths []string
|
|
for _, route := range pageRoutes {
|
|
h := special[route.Method+" "+route.Path]
|
|
if h == nil && route.Page != "" {
|
|
h = s.servePage(route)
|
|
}
|
|
if h == nil {
|
|
continue
|
|
}
|
|
if byPath[route.Path] == nil {
|
|
byPath[route.Path] = map[string]http.HandlerFunc{}
|
|
paths = append(paths, route.Path)
|
|
}
|
|
byPath[route.Path][route.Method] = h
|
|
}
|
|
for _, path := range paths {
|
|
methods := byPath[path]
|
|
notAllowed := s.handleMethodNotAllowed(strings.Join(slices.Sorted(maps.Keys(methods)), ", "))
|
|
r.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) {
|
|
if h, ok := methods[req.Method]; ok {
|
|
h(w, req)
|
|
return
|
|
}
|
|
notAllowed(w, req)
|
|
})
|
|
}
|
|
r.NotFoundHandler = http.HandlerFunc(s.handleNotFoundPage)
|
|
}
|