From 981d2002ceba3e6fe949a0684c924a662d451f60 Mon Sep 17 00:00:00 2001 From: zhaomingqiang Date: Tue, 13 Apr 2021 20:44:33 +0800 Subject: [PATCH] delete gin --- card/http/gin/handler.go | 13 -------- event/http/gin/handler.go | 13 -------- sample/card/gin.go | 6 ++-- sample/card/gin2.go | 36 ---------------------- sample/event/gin.go | 31 ++++++++----------- sample/event/gin2.go | 63 --------------------------------------- 6 files changed, 16 insertions(+), 146 deletions(-) delete mode 100644 card/http/gin/handler.go delete mode 100644 event/http/gin/handler.go delete mode 100644 sample/card/gin2.go delete mode 100644 sample/event/gin2.go diff --git a/card/http/gin/handler.go b/card/http/gin/handler.go deleted file mode 100644 index 48097727..00000000 --- a/card/http/gin/handler.go +++ /dev/null @@ -1,13 +0,0 @@ -package gin - -import ( - "github.com/gin-gonic/gin" - . "github.com/larksuite/oapi-sdk-go/card/http" - "github.com/larksuite/oapi-sdk-go/core/config" -) - -func Register(path string, conf *config.Config, g *gin.Engine) { - g.POST(path, func(context *gin.Context) { - Handle(conf, context.Request, context.Writer) - }) -} diff --git a/event/http/gin/handler.go b/event/http/gin/handler.go deleted file mode 100644 index 7a1017b5..00000000 --- a/event/http/gin/handler.go +++ /dev/null @@ -1,13 +0,0 @@ -package gin - -import ( - "github.com/gin-gonic/gin" - "github.com/larksuite/oapi-sdk-go/core/config" - "github.com/larksuite/oapi-sdk-go/event/http" -) - -func Register(path string, conf *config.Config, g *gin.Engine) { - g.POST(path, func(context *gin.Context) { - http.Handle(conf, context.Request, context.Writer) - }) -} diff --git a/sample/card/gin.go b/sample/card/gin.go index 4a60f43f..6860abec 100644 --- a/sample/card/gin.go +++ b/sample/card/gin.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/larksuite/oapi-sdk-go/card" - cardginserver "github.com/larksuite/oapi-sdk-go/card/http/gin" + cardtttp "github.com/larksuite/oapi-sdk-go/card/http" "github.com/larksuite/oapi-sdk-go/card/model" "github.com/larksuite/oapi-sdk-go/core" "github.com/larksuite/oapi-sdk-go/core/constants" @@ -26,7 +26,9 @@ func main() { }) g := gin.Default() - cardginserver.Register("/webhook/card", conf, g) + g.POST("/webhook/card", func(context *gin.Context) { + cardtttp.Handle(conf, context.Request, context.Writer) + }) err := g.Run(":8089") if err != nil { panic(err) diff --git a/sample/card/gin2.go b/sample/card/gin2.go deleted file mode 100644 index 6860abec..00000000 --- a/sample/card/gin2.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "fmt" - "github.com/gin-gonic/gin" - "github.com/larksuite/oapi-sdk-go/card" - cardtttp "github.com/larksuite/oapi-sdk-go/card/http" - "github.com/larksuite/oapi-sdk-go/card/model" - "github.com/larksuite/oapi-sdk-go/core" - "github.com/larksuite/oapi-sdk-go/core/constants" - "github.com/larksuite/oapi-sdk-go/core/tools" - "github.com/larksuite/oapi-sdk-go/sample/configs" -) - -func main() { - - // for redis store and logrus - // var conf = configs.TestConfigWithLogrusAndRedisStore(constants.DomainFeiShu) - // var conf = configs.TestConfig("https://open.feishu.cn") - var conf = configs.TestConfig(constants.DomainFeiShu) - - card.SetHandler(conf, func(coreCtx *core.Context, card *model.Card) (interface{}, error) { - fmt.Println(coreCtx.GetRequestID()) - fmt.Println(tools.Prettify(card.Action)) - return nil, nil - }) - - g := gin.Default() - g.POST("/webhook/card", func(context *gin.Context) { - cardtttp.Handle(conf, context.Request, context.Writer) - }) - err := g.Run(":8089") - if err != nil { - panic(err) - } -} diff --git a/sample/event/gin.go b/sample/event/gin.go index e954aaaa..c2c49d30 100644 --- a/sample/event/gin.go +++ b/sample/event/gin.go @@ -7,17 +7,17 @@ import ( "github.com/larksuite/oapi-sdk-go/core/constants" "github.com/larksuite/oapi-sdk-go/core/tools" "github.com/larksuite/oapi-sdk-go/event" - eventginserver "github.com/larksuite/oapi-sdk-go/event/http/gin" + eventhttp "github.com/larksuite/oapi-sdk-go/event/http" "github.com/larksuite/oapi-sdk-go/sample/configs" application "github.com/larksuite/oapi-sdk-go/service/application/v1" ) -func main() { +// for redis store and logrus +// var conf = configs.TestConfigWithLogrusAndRedisStore(constants.DomainFeiShu) +// var conf = configs.TestConfig("https://open.feishu.cn") +var conf = configs.TestConfig(constants.DomainFeiShu) - // for redis store and logrus - // var conf = configs.TestConfigWithLogrusAndRedisStore(constants.DomainFeiShu) - // var conf = configs.TestConfig("https://open.feishu.cn") - var conf = configs.TestConfig(constants.DomainFeiShu) +func main() { application.SetAppOpenEventHandler(conf, func(ctx *core.Context, appOpenEvent *application.AppOpenEvent) error { fmt.Println(ctx.GetRequestID()) @@ -49,22 +49,15 @@ func main() { return nil }) - application.SetAppUninstalledEventHandler(conf, func(ctx *core.Context, appUninstalledEvent *application.AppUninstalledEvent) error { - fmt.Println(ctx.GetRequestID()) - fmt.Println(tools.Prettify(appUninstalledEvent)) - return nil - }) - - application.SetOrderPaidEventHandler(conf, func(ctx *core.Context, orderPaidEvent *application.OrderPaidEvent) error { - fmt.Println(ctx.GetRequestID()) - fmt.Println(tools.Prettify(orderPaidEvent)) - return nil - }) - g := gin.Default() - eventginserver.Register("/webhook/event", conf, g) + + g.POST("/webhook/event", webhookEventHandle) err := g.Run(":8089") if err != nil { panic(err) } } + +func webhookEventHandle(context *gin.Context) { + eventhttp.Handle(conf, context.Request, context.Writer) +} diff --git a/sample/event/gin2.go b/sample/event/gin2.go deleted file mode 100644 index c2c49d30..00000000 --- a/sample/event/gin2.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "fmt" - "github.com/gin-gonic/gin" - "github.com/larksuite/oapi-sdk-go/core" - "github.com/larksuite/oapi-sdk-go/core/constants" - "github.com/larksuite/oapi-sdk-go/core/tools" - "github.com/larksuite/oapi-sdk-go/event" - eventhttp "github.com/larksuite/oapi-sdk-go/event/http" - "github.com/larksuite/oapi-sdk-go/sample/configs" - application "github.com/larksuite/oapi-sdk-go/service/application/v1" -) - -// for redis store and logrus -// var conf = configs.TestConfigWithLogrusAndRedisStore(constants.DomainFeiShu) -// var conf = configs.TestConfig("https://open.feishu.cn") -var conf = configs.TestConfig(constants.DomainFeiShu) - -func main() { - - application.SetAppOpenEventHandler(conf, func(ctx *core.Context, appOpenEvent *application.AppOpenEvent) error { - fmt.Println(ctx.GetRequestID()) - fmt.Println(appOpenEvent) - fmt.Println(tools.Prettify(appOpenEvent)) - return nil - }) - - /* - application.SetAppStatusChangeEventHandler(conf, func(ctx *core.Context, appStatusChangeEvent *application.AppStatusChangeEvent) error { - fmt.Println(ctx.GetRequestID()) - fmt.Println(appStatusChangeEvent.Event.AppId) - fmt.Println(appStatusChangeEvent.Event.Status) - fmt.Println(tools.Prettify(appStatusChangeEvent)) - return nil - }) - */ - event.SetTypeCallback(conf, "app_status_change", func(ctx *core.Context, event map[string]interface{}) error { - fmt.Println(ctx.GetRequestID()) - fmt.Println(tools.Prettify(event)) - data := event["event"].(map[string]interface{}) - fmt.Println(tools.Prettify(data)) - return nil - }) - - application.SetAppUninstalledEventHandler(conf, func(ctx *core.Context, appUninstalledEvent *application.AppUninstalledEvent) error { - fmt.Println(ctx.GetRequestID()) - fmt.Println(tools.Prettify(appUninstalledEvent)) - return nil - }) - - g := gin.Default() - - g.POST("/webhook/event", webhookEventHandle) - err := g.Run(":8089") - if err != nil { - panic(err) - } -} - -func webhookEventHandle(context *gin.Context) { - eventhttp.Handle(conf, context.Request, context.Writer) -}