|
@ -6,8 +6,10 @@ import ( |
|
|
"log" |
|
|
"log" |
|
|
"net" |
|
|
"net" |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
"net/http/fcgi" |
|
|
"os" |
|
|
"os" |
|
|
"regexp" |
|
|
"regexp" |
|
|
|
|
|
"strconv" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/GeertJohan/go.rice" |
|
|
"github.com/GeertJohan/go.rice" |
|
@ -24,12 +26,14 @@ var Config struct { |
|
|
allowHotlink bool |
|
|
allowHotlink bool |
|
|
siteName string |
|
|
siteName string |
|
|
siteURL string |
|
|
siteURL string |
|
|
|
|
|
fastcgi bool |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var Templates = make(map[string]*pongo2.Template) |
|
|
var Templates = make(map[string]*pongo2.Template) |
|
|
var TemplateSet *pongo2.TemplateSet |
|
|
var TemplateSet *pongo2.TemplateSet |
|
|
var staticBox *rice.Box |
|
|
var staticBox *rice.Box |
|
|
var timeStarted time.Time |
|
|
var timeStarted time.Time |
|
|
|
|
|
var timeStartedStr string |
|
|
|
|
|
|
|
|
func setup() { |
|
|
func setup() { |
|
|
if Config.noLogs { |
|
|
if Config.noLogs { |
|
@ -70,6 +74,7 @@ func setup() { |
|
|
|
|
|
|
|
|
staticBox = rice.MustFindBox("static") |
|
|
staticBox = rice.MustFindBox("static") |
|
|
timeStarted = time.Now() |
|
|
timeStarted = time.Now() |
|
|
|
|
|
timeStartedStr = strconv.FormatInt(timeStarted.Unix(), 10) |
|
|
|
|
|
|
|
|
// Routing setup
|
|
|
// Routing setup
|
|
|
nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`) |
|
|
nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`) |
|
@ -110,6 +115,8 @@ func main() { |
|
|
"name of the site") |
|
|
"name of the site") |
|
|
flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/", |
|
|
flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/", |
|
|
"site base url (including trailing slash)") |
|
|
"site base url (including trailing slash)") |
|
|
|
|
|
flag.BoolVar(&Config.fastcgi, "fastcgi", false, |
|
|
|
|
|
"serve through fastcgi") |
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
setup() |
|
|
setup() |
|
@ -119,5 +126,9 @@ func main() { |
|
|
log.Fatal("Could not bind: ", err) |
|
|
log.Fatal("Could not bind: ", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if Config.fastcgi { |
|
|
|
|
|
fcgi.Serve(listener, goji.DefaultMux) |
|
|
|
|
|
} else { |
|
|
goji.ServeListener(listener) |
|
|
goji.ServeListener(listener) |
|
|
} |
|
|
} |
|
|
|
|
|
} |