~evanj/cms

ref: da13ad09881f7f92ed44c54cf4cd809f3b31ee57 cms/cms.go -rw-r--r-- 617 bytes
da13ad09Evan J Feat(db): Removed non transactions and deadlocks from db layer. 9 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)
}