This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtattoo.go
76 lines (65 loc) · 1.88 KB
/
tattoo.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"fmt"
"github.com/shellex/tattoo/webapp"
"log"
"os"
"path"
"time"
)
var startUpTime int64
var useFCGI = flag.Bool("fcgi", false, "Use FastCGI")
func LoadTheme(app *webapp.App, themeName string) error {
cfg := GetConfig()
app.Log("Use Theme", themeName)
if err := LoadThemeTemplates(themeName); err != nil {
return err
}
themeURL := path.Join(cfg.Path, "theme", themeName)
themeStaticURL := path.Join(cfg.Path, "theme", themeName, "static")
TattooDB.SetVar("ThemeURL", themeURL)
TattooDB.SetVar("ThemeStaticURL", themeStaticURL)
return nil
}
func main() {
flag.Parse()
if err := GetConfig().Load(); err != nil {
fmt.Println("Failed to load configure file")
return
}
cfg := GetConfig()
startUpTime = time.Now().Unix()
rootPath, _ := os.Getwd()
rootURL := path.Join(cfg.Path, "/")
systemStaticPath := path.Join(rootPath, "/sys/static")
systemStaticURL := path.Join(cfg.Path, "/sys/static")
themePath := path.Join(rootPath, "theme")
themeURL := path.Join(cfg.Path, "/theme")
app := webapp.App{}
app.Log("App Starts", "OK")
app.SetStaticPath(systemStaticURL, systemStaticPath)
app.SetStaticPath(themeURL, themePath)
app.SetHandler(rootURL, HandleRoot)
// Load DB
app.Log("Tattoo DB", "Load DB")
TattooDB.Load(&app)
TattooDB.SetVar("RootURL", rootURL)
TattooDB.SetVar("SystemStaticURL", systemStaticURL)
// load templates
if err := LoadSystemTemplates(); err != nil {
app.Log("Error", fmt.Sprintf("Failed to load system templates: %v", err))
return
}
if err := LoadTheme(&app, GetConfig().ThemeName); err != nil {
app.Log("Error", fmt.Sprintf("Failed to load theme: %v", err))
}
// Start Server.
if *useFCGI {
log.Printf("Server Starts(FastCGI): Listen on port %d\n", GetConfig().Port)
app.RunCGI(GetConfig().Port)
} else {
log.Printf("Server Starts: Listen on port %d\n", GetConfig().Port)
app.Run(GetConfig().Port)
}
}