-
Notifications
You must be signed in to change notification settings - Fork 7
/
gdrj.go
51 lines (44 loc) · 1.22 KB
/
gdrj.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
package main
import (
web "eaciit/gdrj/web"
web2 "eaciit/gdrj/web2"
"eaciit/gdrj/web/installation"
"eaciit/gdrj/web/model"
"fmt"
"github.com/eaciit/knot/knot.v1"
"github.com/eaciit/toolkit"
"net/http"
"strings"
)
func main() {
port := new(gocore.Ports)
port.ID = "port"
if err := port.GetPort(); err != nil {
toolkit.Printf("Error get port: %s \n", err.Error())
}
if port.Port == 0 {
if err := setup.Port(port); err != nil {
toolkit.Printf("Error set port: %s \n", err.Error())
}
}
flagAddress := toolkit.Sprintf("localhost:%v", toolkit.ToString(port.Port))
appConf := knot.AppContainerConfig{Address: flagAddress}
otherRoutes := map[string]knot.FnContent{
"/": func(r *knot.WebContext) interface{} {
rURL := r.Request.URL.String()
prefix := web.AppName
if strings.Contains(rURL, web2.AppName) {
prefix = web2.AppName
}
sessionid := r.Session("sessionid", "")
if sessionid == "" {
http.Redirect(r.Writer, r.Request, fmt.Sprintf("/%s/page/login", prefix), 301)
} else {
http.Redirect(r.Writer, r.Request, fmt.Sprintf("/%s/page/dashboard", prefix), 301)
}
return true
},
}
knot.DefaultOutputType = knot.OutputTemplate
knot.StartContainerWithFn(&appConf, otherRoutes)
}