forked from UniqueStudio/open-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
114 lines (90 loc) · 2.83 KB
/
main.go
File metadata and controls
114 lines (90 loc) · 2.83 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
nice "github.com/ekyoung/gin-nice-recovery"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"net/http"
"open-platform/handler"
"open-platform/middleware"
"open-platform/utils"
)
func main() {
gin.SetMode(gin.ReleaseMode)
r := gin.New()
r.Use(gin.Logger())
// CORS support
r.Use(middleware.CORSMiddleware())
// Recovery from internal server error
r.Use(nice.Recovery(handler.RecoveryHandler))
// Static files
r.Use(static.Serve("/static", static.LocalFile("./static", true)))
store := cookie.NewStore([]byte(utils.AppConfig.Server.SecretKey))
r.Use(sessions.Sessions("Status", store))
r.LoadHTMLGlob("static/*/*.tmpl")
html := r.Group("/")
html.Use(middleware.Login())
html.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.tmpl", nil) })
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.GET("/test", handler.GenAuthTokenHandler)
r.GET("/login", handler.LoginHandler)
r.GET("/login/:app", handler.LoginHandler)
r.GET("/logout", handler.LogoutHandler)
r.GET("/check", handler.CheckAuthorityHandler)
r.GET("/api", handler.GenAccessKeyHandler)
app := r.Group("/app")
app.Use(middleware.Login())
{
app.GET("/:app", handler.RenderAppStaticFilesHandler)
// TODO app.StaticFS("/message/", http.Dir("./static/message/dist/"))
}
login := r.Group("/")
login.Use(middleware.Login())
{
login.GET("/decode", handler.DecodeHandler)
}
r.GET("/auth", handler.AuthHandler)
r.GET("/auth/:app", handler.AuthAPPHandler)
weixin := r.Group("/weixin")
weixin.Use(middleware.Auth())
{
weixin.GET("/department", handler.GetDepartmentListHandler)
weixin.GET("/department/:departmentID", handler.GetDepartmentUsersHandler)
weixin.PATCH("/user/:userID", handler.UpdateUserInfoHandler)
}
Sms := r.Group("/sms")
Sms.Use(middleware.Auth())
{
Sms.POST("/send_single", handler.SendSingleSMSHandler)
Sms.POST("/send_group", handler.SendGroupSMSHandle)
Sms.GET("/templates", handler.GetTemplatesHandler)
Sms.GET("/reply_callback", handler.ReplyCallbackHandler)
}
open := r.Group("/open")
open.Use(middleware.Auth())
{
open.GET("/permission", handler.GetPermissionHandler)
}
mail := r.Group("/mail")
mail.Use(middleware.Auth())
{
mail.POST("/send_mail", handler.SendMailHandler)
}
r.GET("/v/:Shorturl", handler.MapShortUrlHandler)
r.GET("/genUrl", middleware.Auth(), handler.CreateShortUrlHandler)
showStatus()
// Run Server
r.Run(utils.AppConfig.Server.Host + ":" + utils.AppConfig.Server.Port)
}
func showStatus() {
fmt.Println("\n===================================" +
"\nAPP : " + utils.AppConfig.APPName +
"\nRunning On : " + utils.AppConfig.Server.Host + ":" + utils.AppConfig.Server.Port +
"\n===================================")
}