]> Sergey Matveev's repositories - godlighty.git/blob - rc/example.cfg/blog.stargrave.org.go
Verbose redirects, tiny DRY
[godlighty.git] / rc / example.cfg / blog.stargrave.org.go
1 package cfg
2
3 import (
4         "net/http"
5         "net/http/cgi"
6         "path"
7         "strings"
8
9         "go.stargrave.org/godlighty"
10         "go.stargrave.org/godlighty/rc"
11 )
12
13 func init() {
14         host := "blog.stargrave.org"
15         godlighty.Hosts[host] = &godlighty.HostCfg{
16                 Root: path.Join(WWW, host),
17                 TLS:  newTLSCfg(host),
18                 Hooks: []godlighty.Hook{
19                         func(w http.ResponseWriter, r *http.Request) bool {
20                                 var t string
21                                 if strings.HasPrefix(r.URL.Path, "/russian") {
22                                         t = "russian"
23                                 } else if strings.HasPrefix(r.URL.Path, "/english") {
24                                         t = "english"
25                                 } else if strings.HasPrefix(r.URL.Path, "/example") {
26                                         t = "example"
27                                 }
28                                 if t == "" {
29                                         return false
30                                 }
31                                 r.URL.Path = strings.TrimPrefix(r.URL.Path, "/"+t)
32                                 rc.RunCGIAndLog(host, w, r, &cgi.Handler{
33                                         Path: "/home/sgblog/sgblog",
34                                         Dir:  "/var/empty",
35                                         Env:  []string{"SGBLOG_CFG=/home/sgblog/" + t + ".hjson"},
36                                 })
37                                 return true
38                         },
39                 },
40         }
41 }