mtfosbot/router/routes/routes.go

96 lines
2.7 KiB
Go
Raw Normal View History

2018-08-14 09:25:34 +00:00
package routes
import (
2018-09-18 15:54:36 +00:00
"fmt"
2018-09-02 01:15:27 +00:00
"log"
2018-09-19 12:23:39 +00:00
"git.trj.tw/golang/mtfosbot/module/config"
2018-09-02 01:15:27 +00:00
"git.trj.tw/golang/mtfosbot/module/context"
"git.trj.tw/golang/mtfosbot/router/api"
2018-09-15 15:09:41 +00:00
"git.trj.tw/golang/mtfosbot/router/google"
"git.trj.tw/golang/mtfosbot/router/line"
2018-09-18 15:54:36 +00:00
"git.trj.tw/golang/mtfosbot/router/rimg"
"git.trj.tw/golang/mtfosbot/router/twitch"
2018-08-14 09:25:34 +00:00
"github.com/gin-contrib/cors"
2018-09-02 01:15:27 +00:00
"github.com/gin-gonic/contrib/sessions"
2018-08-14 09:25:34 +00:00
"github.com/gin-gonic/gin"
)
// NewServ - create new gin server
func NewServ() *gin.Engine {
r := gin.New()
2018-09-02 01:15:27 +00:00
2018-09-19 12:23:39 +00:00
conf := config.GetConf()
redisStr := fmt.Sprintf("%s:%d", conf.Redis.Host, conf.Redis.Port)
store, err := sessions.NewRedisStore(10, "tcp", redisStr, "", []byte("seckey"))
2018-09-02 01:15:27 +00:00
if err != nil {
log.Fatal(err)
}
2018-08-14 09:25:34 +00:00
// access log
r.Use(gin.Logger())
// error catch
r.Use(gin.Recovery())
// enable cors
r.Use(cors.Default())
2018-09-02 01:15:27 +00:00
// session
2018-09-02 03:24:40 +00:00
r.Use(sessions.Sessions("ginsess", store))
2018-09-02 01:15:27 +00:00
2018-08-14 09:25:34 +00:00
return r
}
// SetRoutes - set routes
func SetRoutes(r *gin.Engine) {
r.GET("/", func(c *gin.Context) {
fmt.Println("in next")
2018-08-14 09:25:34 +00:00
c.JSON(200, gin.H{
"message": "ok",
})
})
2018-09-02 01:15:27 +00:00
2018-09-18 15:54:36 +00:00
imageProcGroup := r.Group("/image")
{
imageProcGroup.GET("/origin/:imgname", context.PatchCtx(rimg.GetOriginImage))
2018-09-19 09:26:36 +00:00
imageProcGroup.GET("/thumbnail/:imgname", context.PatchCtx(rimg.GetThumbnailImage))
2018-09-18 15:54:36 +00:00
}
2018-09-02 01:15:27 +00:00
apiGroup := r.Group("/api")
{
apiGroup.POST("/login", context.PatchCtx(api.UserLogin))
apiGroup.POST("/logout", context.PatchCtx(api.UserLogout))
2018-09-18 15:54:36 +00:00
apiGroup.GET("/twitch/channel/:chid/opay/bar", context.PatchCtx(api.GetDonateBarStatus))
2018-09-02 01:15:27 +00:00
}
2018-09-17 16:35:48 +00:00
apiTwitchGroup := apiGroup.Group("/twitch", context.PatchCtx(api.CheckSession))
{
apiTwitchGroup.GET("/channels", context.PatchCtx(api.GetChannels), context.PatchCtx(api.GetChannelList))
twitchChannelGroup := apiTwitchGroup.Group("/channel/:chid", context.PatchCtx(api.GetChannels))
{
twitchChannelGroup.GET("/", context.PatchCtx(api.GetChannelData))
twitchChannelGroup.PUT("/botjoin", context.PatchCtx(api.BotJoinChannel))
twitchChannelGroup.PUT("/opay", context.PatchCtx(api.OpayIDChange))
twitchChannelGroup.GET("/opay/setting", context.PatchCtx(api.GetDonateSetting))
twitchChannelGroup.PUT("/opay/setting", context.PatchCtx(api.UpdateDonateSetting))
}
}
2018-09-15 15:09:41 +00:00
lineApis := r.Group("/line")
{
lineApis.POST("/", context.PatchCtx(line.GetRawBody), context.PatchCtx(line.VerifyLine), context.PatchCtx(line.GetLineMessage))
}
googleApis := r.Group("/google")
{
googleApis.GET("/youtube/webhook", context.PatchCtx(google.VerifyWebhook))
googleApis.POST("/youtube/webhook", context.PatchCtx(google.GetNotifyWebhook))
}
twitchApis := r.Group("/twitch")
{
twitchApis.GET("/login", context.PatchCtx(twitch.OAuthLogin))
twitchApis.GET("/oauth", context.PatchCtx(twitch.OAuthProc))
}
2018-08-14 09:25:34 +00:00
}