~evanj/cms

ref: 5eb977545bd0bfaacf289952a8b7f5a273168ab6 cms/cms.go -rw-r--r-- 617 bytes
5eb97754Evan M Jones Chore(Error2 -> Error): Swapped Error impl. for Error2 in all 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// cms is a free and open source content management system.
package main

import (
	"log"
	"net/http"
	"strings"
)

type App struct {
	log *log.Logger

	// NOTE: Concurrent read (only) is OK. This is never wrote (but defined on
	// server startup).
	handlers map[string]http.Handler
}

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	parts := strings.Split(r.URL.Path, "/")
	if len(parts) < 2 {
		http.NotFound(w, r)
		return
	}

	namespace := parts[1]
	if namespace == "" {
		namespace = "user"
	}

	h, ok := a.handlers[namespace]
	if !ok {
		http.NotFound(w, r)
		return
	}

	h.ServeHTTP(w, r)
}