add context path support
This commit is contained in:
parent
56f3fa1cf6
commit
29ae107de4
16
conf/wide.go
16
conf/wide.go
|
@ -249,7 +249,7 @@ func Save() bool {
|
|||
}
|
||||
|
||||
// Load loads the configurations from wide.json.
|
||||
func Load(confPath, confIP, confPort, confServer, confContext, confChannel string, confDocker bool) {
|
||||
func Load(confPath, confIP, confPort, confServer, confStaticServer, confContext, confChannel string, confDocker bool) {
|
||||
bytes, _ := ioutil.ReadFile(confPath)
|
||||
|
||||
err := json.Unmarshal(bytes, &Wide)
|
||||
|
@ -262,8 +262,7 @@ func Load(confPath, confIP, confPort, confServer, confContext, confChannel strin
|
|||
// keep the raw content
|
||||
json.Unmarshal(bytes, &rawWide)
|
||||
|
||||
// upgrade if need
|
||||
upgrade()
|
||||
glog.V(5).Info("Conf: \n" + string(bytes))
|
||||
|
||||
// Working Driectory
|
||||
Wide.WD = util.OS.Pwd()
|
||||
|
@ -299,13 +298,17 @@ func Load(confPath, confIP, confPort, confServer, confContext, confChannel strin
|
|||
Wide.Server = confServer
|
||||
}
|
||||
|
||||
// Static Server
|
||||
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", Wide.IP, 1)
|
||||
if "" != confStaticServer {
|
||||
Wide.StaticServer = confStaticServer
|
||||
}
|
||||
|
||||
// Context
|
||||
if "" != confContext {
|
||||
Wide.Context = confContext
|
||||
}
|
||||
|
||||
// Static Server
|
||||
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", Wide.IP, 1)
|
||||
Wide.StaticResourceVersion = strings.Replace(Wide.StaticResourceVersion, "${time}", strconv.FormatInt(time.Now().UnixNano(), 10), 1)
|
||||
|
||||
// Channel
|
||||
|
@ -318,7 +321,8 @@ func Load(confPath, confIP, confPort, confServer, confContext, confChannel strin
|
|||
Wide.Server = strings.Replace(Wide.Server, "{Port}", Wide.Port, 1)
|
||||
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{Port}", Wide.Port, 1)
|
||||
|
||||
glog.V(5).Info("Conf: \n" + string(bytes))
|
||||
// upgrade if need
|
||||
upgrade()
|
||||
|
||||
initWorkspaceDirs()
|
||||
initCustomizedConfs()
|
||||
|
|
15
main.go
15
main.go
|
@ -47,6 +47,7 @@ func init() {
|
|||
confIP := flag.String("ip", "", "ip to visit")
|
||||
confPort := flag.String("port", "", "port to visit")
|
||||
confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
|
||||
confStaticServer := flag.String("static_server", "", "this will overwrite Wide.StaticServer if specified")
|
||||
confContext := flag.String("context", "", "this will overwrite Wide.Context if specified")
|
||||
confChannel := flag.String("channel", "", "this will overwrite Wide.XXXChannel if specified")
|
||||
confStat := flag.Bool("stat", false, "whether report statistics periodically")
|
||||
|
@ -69,7 +70,7 @@ func init() {
|
|||
|
||||
event.Load()
|
||||
|
||||
conf.Load(*confPath, *confIP, *confPort, *confServer, *confContext, *confChannel, *confDocker)
|
||||
conf.Load(*confPath, *confIP, *confPort, *confServer, *confStaticServer, *confContext, *confChannel, *confDocker)
|
||||
|
||||
conf.FixedTimeCheckEnv()
|
||||
conf.FixedTimeSave()
|
||||
|
@ -91,6 +92,9 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
// create a Wide session
|
||||
|
@ -148,6 +152,9 @@ func startHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
@ -185,6 +192,9 @@ func keyboardShortcutsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
@ -214,6 +224,9 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
|
|
@ -54,6 +54,9 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
@ -186,6 +189,9 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||
httpSession.Values["username"] = args.Username
|
||||
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
glog.Infof("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), args.Username)
|
||||
|
|
|
@ -49,6 +49,9 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
if "" != conf.Wide.Context {
|
||||
httpSession.Options.Path = conf.Wide.Context
|
||||
}
|
||||
httpSession.Save(r, w)
|
||||
|
||||
// create a wide session
|
||||
|
|
Loading…
Reference in New Issue