-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththyself.go
77 lines (62 loc) · 2.5 KB
/
thyself.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
77
package main
// mux, session, schema, context
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
"thyself/data"
"thyself/log"
"thyself/web"
"flag"
)
var isDev bool;
func initServer() {
web.LoadTemplates(isDev) // Loads the template for all of the pages into memory
globalRouter := mux.NewRouter()
// Pages
globalRouter.HandleFunc("/", web.HomepageHandler)
//globalRouter.HandleFunc("/journal", web.JournalHandler)
// View some detail about a user.
globalRouter.HandleFunc("/u/{user_id}/{year}/{month}/{day}", web.JournalHandler) // POST for updating journal
globalRouter.HandleFunc("/u/{user_id}/{year}/{month}/{day}/m", web.EntriesHandler) // POST for adding/parsing entries. Will redirecto to newly created entry page
globalRouter.HandleFunc("/u/{user_id}/{year}/{month}/{day}/m/{metric_name}/e/{entry_id}/{entry_desc}", web.JournalHandler) // TODO - Entry summary
// Account Management - authorized for self only
globalRouter.HandleFunc("/a", web.HomepageHandler)
globalRouter.HandleFunc("/a/login", web.LoginHandler)
globalRouter.HandleFunc("/a/logout", web.LogoutHandler)
globalRouter.HandleFunc("/a/register", web.RegisterHandler)
// putting it in account for now cuz I don't want the ajax trying to load this link
globalRouter.HandleFunc("/a/terms", web.TermsHandler)
// i = informational. For site-support pages like
// demo, api docs, blog, etc.
globalRouter.HandleFunc("/i/demo", web.DemoHandler)
globalRouter.HandleFunc("/i/demo/m", web.DemoParseHandler)
// Parse will be handled here too
apiRouter := globalRouter.PathPrefix("/api/v0/").Subrouter()
apiRouter.HandleFunc("/entries", web.EntryListHandler)
apiRouter.HandleFunc("/entries/", web.EntryListHandler)
apiRouter.HandleFunc("/entries/{entry_id}", web.EntryItemHandler)
// Queries("key", "value")
http.Handle("/", globalRouter)
http.ListenAndServe(":8080", nil)
}
func main() {
fmt.Println("Starting Thyself.io Server")
//startTime := time.Now()
log.InitLog()
devPtr := flag.Bool("dev",false,"Toggles dev mode (use local scripts, headers and enable debug code)")
flag.Parse()
isDev = *devPtr
if isDev{
fmt.Println("RUNNING IN DEVELOPMENT MODE")
log.Info("WARNING: Running in Development Mode")
}else {
fmt.Println("Running in production mode")
log.Info("Running in production mode")
}
data.RedisInit()
data.SqlInit()
log.Info("Server started")
initServer()
//shared.Log.Println("\n Server ran for %s \n ", time.Since(startTime))
}