package main import ( "encoding/gob" "log" "net/http" "os" b "streifling.com/jason/cpolis/cmd/backend" c "streifling.com/jason/cpolis/cmd/calls" f "streifling.com/jason/cpolis/cmd/frontend" ) func init() { gob.Register(b.User{}) } func main() { config, err := b.HandleConfig() if err != nil { log.Fatalln(err) } logFile, err := os.OpenFile(config.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Fatalln(err) } defer logFile.Close() log.SetOutput(logFile) db, err := b.OpenDB(config.DBName) if err != nil { log.Fatalln(err) } defer db.Close() key, err := b.LoadKey(config.KeyFile) if err != nil { key, err = b.NewKey() if err != nil { log.Fatalln(err) } b.SaveKey(key, config.KeyFile) } store := b.NewCookieStore(key) mux := http.NewServeMux() mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir(config.WebDir+"/static/")))) mux.HandleFunc("/", f.HomePage(config, db, store)) mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db)) mux.HandleFunc("GET /create-tag", f.CreateTag(config, store)) mux.HandleFunc("GET /create-user", f.CreateUser(config, store)) mux.HandleFunc("GET /delete-article/{id}", f.DeleteArticle(config, db, store)) mux.HandleFunc("GET /delete-user/{id}", f.DeleteUser(config, db, store)) mux.HandleFunc("GET /edit-self", f.EditSelf(config, db, store)) mux.HandleFunc("GET /edit-user/{id}", f.EditUser(config, db, store)) mux.HandleFunc("GET /hub", f.ShowHub(config, db, store)) mux.HandleFunc("GET /logout", f.Logout(config, store)) mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config)) mux.HandleFunc("GET /pdf/{id}", c.ServePDF(config)) 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 /published-articles", f.ShowPublishedArticles(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-article-for-deletion/{id}", f.ReviewArticleForDeletion(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", c.ServeRSS(config)) 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, store)) mux.HandleFunc("GET /unpublished-articles", f.ShowUnpublishedArticles(config, db, store)) mux.HandleFunc("GET /write-article", f.WriteArticle(config, db, store)) 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 /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, store)) log.Fatalln(http.ListenAndServe(config.Port, mux)) }