wide/main.go

68 lines
1.5 KiB
Go
Raw Normal View History

2014-08-18 17:45:43 +04:00
package main
import (
2014-08-18 17:51:03 +04:00
"github.com/b3log/wide/conf"
"github.com/b3log/wide/editor"
"github.com/b3log/wide/file"
2014-08-25 18:17:02 +04:00
"github.com/b3log/wide/i18n"
2014-08-18 17:51:03 +04:00
"github.com/b3log/wide/output"
"github.com/b3log/wide/session"
"github.com/b3log/wide/shell"
2014-08-18 17:45:43 +04:00
"github.com/golang/glog"
"html/template"
"math/rand"
"net/http"
"strconv"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
2014-08-25 18:17:02 +04:00
model := map[string]interface{}{"Wide": conf.Wide, "i18n": i18n.GetLangs(r)}
2014-08-18 17:45:43 +04:00
session, _ := session.Store.Get(r, "wide-session")
if session.IsNew {
session.Values["id"] = strconv.Itoa(rand.Int())
}
session.Save(r, w)
t, err := template.ParseFiles("templates/index.html")
if nil != err {
glog.Error(err)
http.Error(w, err.Error(), 500)
return
}
2014-08-25 18:17:02 +04:00
t.Execute(w, model)
2014-08-18 17:45:43 +04:00
}
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", indexHandler)
2014-08-22 07:57:05 +04:00
http.HandleFunc("/build", output.BuildHandler)
2014-08-18 17:45:43 +04:00
http.HandleFunc("/run", output.RunHandler)
http.HandleFunc("/output/ws", output.WSHandler)
http.HandleFunc("/files", file.GetFiles)
http.HandleFunc("/file", file.GetFile)
http.HandleFunc("/file/save", file.SaveFile)
http.HandleFunc("/file/new", file.NewFile)
http.HandleFunc("/file/remove", file.RemoveFile)
http.HandleFunc("/editor/ws", editor.WSHandler)
http.HandleFunc("/fmt", editor.FmtHandler)
http.HandleFunc("/shell/ws", shell.WSHandler)
http.HandleFunc("/autocomplete", editor.AutocompleteHandler)
err := http.ListenAndServe(conf.Wide.Server, nil)
if err != nil {
glog.Fatal(err)
}
}