-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (73 loc) · 1.99 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"log"
"github.com/micro/go-micro/v2"
"github.com/ghosv/open/gate/conf"
"github.com/ghosv/open/gate/handler"
"github.com/ghosv/open/gate/middleware"
"github.com/ghosv/open/meta"
"github.com/ddosakura/sola/v2"
"github.com/ddosakura/sola/v2/middleware/native"
"github.com/ddosakura/sola/v2/middleware/proxy"
"github.com/ddosakura/sola/v2/middleware/router"
)
func initClient() micro.Service {
// New Service
service := micro.NewService(
micro.Name(meta.ClientGateway),
micro.Version(meta.Version),
)
// Initialise Service
service.Init()
return service
}
func main() {
// TODO: Optional
cfg := conf.Default
loadService := middleware.LoadService(initClient())
sola.Use(proxy.Favicon(cfg.Favicon))
sola.DefaultApp.LoadConfig()
// TODO: move to sola project
sola.Use(func(next sola.Handler) sola.Handler {
return func(c sola.Context) error {
c.Response().Header().Set("X-Sola", "v2")
return next(c)
}
})
{
r := router.New(nil)
r.Bind("GET /", handler.HomePage)
r.Use(loadService)
// notify
// TODO: 发送 code 注意限频率
r.Bind("GET /notify/post/code", handler.NotifyPostAuthCode)
{
sub := r.Sub(&router.Option{Pattern: "/tmp"})
handler.InjectTempService(sub)
}
// oauth2
r.Bind("GET /authorize", handler.Authorize) // TODO: 兼容已登录状态下免填token
r.Bind("GET /authorize_confirm", handler.AuthorizeConfirm)
r.Bind("POST /access_token", handler.AccessToken)
r.Bind("POST /register", handler.Register)
r.Bind("POST /login", handler.Login)
// r.Bind("/logout", h)
r.Use(middleware.Auth)
// Check Login Status
r.Bind("/status", handler.Status)
{
sub := r.Sub(&router.Option{Pattern: "/tmp2"})
handler.InjectTempService2(sub)
}
r.Bind("POST /graphql", handler.DefaultGraphQL)
{
sub := r.Sub(&router.Option{Pattern: "/api"})
// TODO
sub.Bind("/test", nil)
}
sola.Use(r.Routes())
}
sola.Use(native.Static("static", ""))
log.Println(conf.ReadyServer)
sola.ListenKeep(cfg.Addr)
}