/
manager.go
76 lines (63 loc) · 1.51 KB
/
manager.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package manager
import (
"encoding/json"
"fmt"
"net/http"
"net/http/pprof"
"dearcode.net/crab/log"
"github.com/juju/errors"
"dearcode.net/doodle/pkg/manager/config"
"dearcode.net/doodle/pkg/util"
)
var (
userdb = newUserDB()
session = newSession()
)
type account struct {
}
// GET 获取用户帐号信息
func (a *account) GET(w http.ResponseWriter, r *http.Request) {
i, err := session.User(w, r)
if err != nil {
log.Errorf("get session user error:%v", errors.ErrorStack(err))
util.SendResponse(w, http.StatusInternalServerError, err.Error())
return
}
buf, err := json.Marshal(i)
if err != nil {
util.SendResponse(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(buf)
}
type serverCfg struct {
}
// onDomainGet 获取配置文件中域名
func (c *serverCfg) GET(w http.ResponseWriter, r *http.Request) {
resp := struct {
Domain string
SSOURL string
}{
Domain: config.Manager.Server.Domain,
SSOURL: config.Manager.SSO.URL,
}
util.SendResponseJSON(w, resp)
}
type static struct {
}
// GET 静态文件
func (s *static) GET(w http.ResponseWriter, r *http.Request) {
_, err := session.User(w, r)
if err != nil {
log.Errorf("%v", errors.ErrorStack(err))
}
// w.Header().Add("Cache-control", "no-store")
path := fmt.Sprintf("%s%s", config.Manager.Server.WebPath, r.URL.Path)
http.ServeFile(w, r, path)
}
type debug struct {
}
func (d *debug) GET(w http.ResponseWriter, r *http.Request) {
pprof.Index(w, r)
}