forked from jason/cpolis
Shorten lines by referencing frontend as f and backend as b
This commit is contained in:
82
cmd/main.go
82
cmd/main.go
@@ -6,16 +6,16 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"streifling.com/jason/cpolis/cmd/backend"
|
||||
"streifling.com/jason/cpolis/cmd/frontend"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
f "streifling.com/jason/cpolis/cmd/frontend"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gob.Register(backend.User{})
|
||||
gob.Register(b.User{})
|
||||
}
|
||||
|
||||
func main() {
|
||||
config, err := backend.HandleConfig()
|
||||
config, err := b.HandleConfig()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -27,60 +27,58 @@ func main() {
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
|
||||
db, err := backend.OpenDB(config.DBName)
|
||||
db, err := b.OpenDB(config.DBName)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
key, err := backend.LoadKey(config.KeyFile)
|
||||
key, err := b.LoadKey(config.KeyFile)
|
||||
if err != nil {
|
||||
key, err = backend.NewKey()
|
||||
key, err = b.NewKey()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
backend.SaveKey(key, config.KeyFile)
|
||||
b.SaveKey(key, config.KeyFile)
|
||||
}
|
||||
store := backend.NewCookieStore(key)
|
||||
store := b.NewCookieStore(key)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
||||
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
||||
mux.HandleFunc("/", frontend.HomePage(config, db, store))
|
||||
mux.HandleFunc("/", f.HomePage(config, db, store))
|
||||
|
||||
mux.HandleFunc("GET /create-tag", frontend.CreateTag(config))
|
||||
mux.HandleFunc("GET /create-user", frontend.CreateUser(config))
|
||||
mux.HandleFunc("GET /edit-self", frontend.EditSelf(config, db, store))
|
||||
mux.HandleFunc("GET /edit-user/{id}", frontend.EditUser(config, db))
|
||||
mux.HandleFunc("GET /delete-user/{id}", frontend.DeleteUser(config, db, store))
|
||||
mux.HandleFunc("GET /hub", frontend.ShowHub(config, db, store))
|
||||
mux.HandleFunc("GET /logout", frontend.Logout(config, store))
|
||||
mux.HandleFunc("GET /pics/{pic}", frontend.ServeImage(config, store))
|
||||
mux.HandleFunc("GET /publish-article/{id}", frontend.PublishArticle(config, db, store))
|
||||
mux.HandleFunc("GET /publish-issue", frontend.PublishLatestIssue(config, db, store))
|
||||
mux.HandleFunc("GET /reject-article/{id}", frontend.RejectArticle(config, db, store))
|
||||
mux.HandleFunc("GET /rejected-articles", frontend.ShowRejectedArticles(config, db, store))
|
||||
mux.HandleFunc("GET /review-rejected-article/{id}", frontend.ReviewRejectedArticle(config, db, store))
|
||||
mux.HandleFunc("GET /review-unpublished-article/{id}", frontend.ReviewUnpublishedArticle(config, db, store))
|
||||
mux.HandleFunc("GET /rss", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, config.RSSFile)
|
||||
})
|
||||
mux.HandleFunc("GET /show-all-users-edit", frontend.ShowAllUsers(config, db, store, "edit-user"))
|
||||
mux.HandleFunc("GET /show-all-users-delete", frontend.ShowAllUsers(config, db, store, "delete-user"))
|
||||
mux.HandleFunc("GET /this-issue", frontend.ShowCurrentArticles(config, db))
|
||||
mux.HandleFunc("GET /unpublished-articles", frontend.ShowUnpublishedArticles(config, db))
|
||||
mux.HandleFunc("GET /write-article", frontend.WriteArticle(config, db))
|
||||
mux.HandleFunc("GET /create-tag", f.CreateTag(config))
|
||||
mux.HandleFunc("GET /create-user", f.CreateUser(config))
|
||||
mux.HandleFunc("GET /edit-self", f.EditSelf(config, db, store))
|
||||
mux.HandleFunc("GET /edit-user/{id}", f.EditUser(config, db))
|
||||
mux.HandleFunc("GET /delete-user/{id}", f.DeleteUser(config, db, store))
|
||||
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
||||
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
||||
mux.HandleFunc("GET /pics/{pic}", f.ServeImage(config, store))
|
||||
mux.HandleFunc("GET /publish-article/{id}", f.PublishArticle(config, db, store))
|
||||
mux.HandleFunc("GET /publish-issue", f.PublishLatestIssue(config, db, store))
|
||||
mux.HandleFunc("GET /reject-article/{id}", f.RejectArticle(config, db, store))
|
||||
mux.HandleFunc("GET /rejected-articles", f.ShowRejectedArticles(config, db, store))
|
||||
mux.HandleFunc("GET /review-rejected-article/{id}", f.ReviewRejectedArticle(config, db, store))
|
||||
mux.HandleFunc("GET /review-unpublished-article/{id}", f.ReviewUnpublishedArticle(config, db, store))
|
||||
mux.HandleFunc("GET /rss", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, config.RSSFile) })
|
||||
mux.HandleFunc("GET /show-all-users-edit", f.ShowAllUsers(config, db, store, "edit-user"))
|
||||
mux.HandleFunc("GET /show-all-users-delete", f.ShowAllUsers(config, db, store, "delete-user"))
|
||||
mux.HandleFunc("GET /this-issue", f.ShowCurrentArticles(config, db))
|
||||
mux.HandleFunc("GET /unpublished-articles", f.ShowUnpublishedArticles(config, db))
|
||||
mux.HandleFunc("GET /write-article", f.WriteArticle(config, db))
|
||||
|
||||
mux.HandleFunc("POST /add-first-user", frontend.AddFirstUser(config, db, store))
|
||||
mux.HandleFunc("POST /add-tag", frontend.AddTag(config, db, store))
|
||||
mux.HandleFunc("POST /add-user", frontend.AddUser(config, db, store))
|
||||
mux.HandleFunc("POST /login", frontend.Login(config, db, store))
|
||||
mux.HandleFunc("POST /preview-article", frontend.PreviewArticle(config, store))
|
||||
mux.HandleFunc("POST /resubmit-article/{id}", frontend.ResubmitArticle(config, db, store))
|
||||
mux.HandleFunc("POST /submit-article", frontend.SubmitArticle(config, db, store))
|
||||
mux.HandleFunc("POST /update-self", frontend.UpdateSelf(config, db, store))
|
||||
mux.HandleFunc("POST /update-user/{id}", frontend.UpdateUser(config, db, store))
|
||||
mux.HandleFunc("POST /upload-image", frontend.UploadImage(config))
|
||||
mux.HandleFunc("POST /add-first-user", f.AddFirstUser(config, db, store))
|
||||
mux.HandleFunc("POST /add-tag", f.AddTag(config, db, store))
|
||||
mux.HandleFunc("POST /add-user", f.AddUser(config, db, store))
|
||||
mux.HandleFunc("POST /login", f.Login(config, db, store))
|
||||
mux.HandleFunc("POST /preview-article", f.PreviewArticle(config, store))
|
||||
mux.HandleFunc("POST /resubmit-article/{id}", f.ResubmitArticle(config, db, store))
|
||||
mux.HandleFunc("POST /submit-article", f.SubmitArticle(config, db, store))
|
||||
mux.HandleFunc("POST /update-self", f.UpdateSelf(config, db, store))
|
||||
mux.HandleFunc("POST /update-user/{id}", f.UpdateUser(config, db, store))
|
||||
mux.HandleFunc("POST /upload-image", f.UploadImage(config))
|
||||
|
||||
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
||||
}
|
||||
|
Reference in New Issue
Block a user