diff --git a/event/core/handlers/handlers.go b/event/core/handlers/handlers.go index c0b0d904..c8583d92 100644 --- a/event/core/handlers/handlers.go +++ b/event/core/handlers/handlers.go @@ -115,9 +115,7 @@ func complementFunc(ctx *core.Context, httpEvent *model.HTTPEvent) { conf := config.ByCtx(ctx) err := httpEvent.Err if err != nil { - switch e := err.(type) { - case *NotFoundHandlerErr: - conf.GetLogger().Info(ctx, e.Error()) + if _, ok := err.(*NotFoundHandlerErr); ok { httpEvent.Response.Write(http.StatusOK, constants.DefaultContentType, fmt.Sprintf(coremodel.ResponseFormat, err.Error())) return } diff --git a/sample/event/contact.go b/sample/event/contact.go index cda1e5f2..496e7ec2 100644 --- a/sample/event/contact.go +++ b/sample/event/contact.go @@ -6,6 +6,7 @@ import ( "github.com/larksuite/oapi-sdk-go/core" "github.com/larksuite/oapi-sdk-go/core/constants" "github.com/larksuite/oapi-sdk-go/core/tools" + eventhttp "github.com/larksuite/oapi-sdk-go/event/http" "github.com/larksuite/oapi-sdk-go/sample/configs" contact "github.com/larksuite/oapi-sdk-go/service/contact/v3" ) @@ -36,7 +37,9 @@ func main() { }) g := gin.Default() - g.POST("/webhook/event", webhookEventHandle) + g.POST("/webhook/event", func(context *gin.Context) { + eventhttp.Handle(conf, context.Request, context.Writer) + }) err := g.Run(":8089") if err != nil { fmt.Println(err) diff --git a/sample/event/gin.go b/sample/event/gin.go index c2c49d30..517ff3ba 100644 --- a/sample/event/gin.go +++ b/sample/event/gin.go @@ -51,13 +51,11 @@ func main() { g := gin.Default() - g.POST("/webhook/event", webhookEventHandle) + g.POST("/webhook/event", func(context *gin.Context) { + eventhttp.Handle(conf, context.Request, context.Writer) + }) 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/im.go b/sample/event/im.go index a78f71d0..e5df3261 100644 --- a/sample/event/im.go +++ b/sample/event/im.go @@ -6,6 +6,7 @@ import ( "github.com/larksuite/oapi-sdk-go/core" "github.com/larksuite/oapi-sdk-go/core/constants" "github.com/larksuite/oapi-sdk-go/core/tools" + eventhttp "github.com/larksuite/oapi-sdk-go/event/http" "github.com/larksuite/oapi-sdk-go/sample/configs" im "github.com/larksuite/oapi-sdk-go/service/im/v1" ) @@ -24,7 +25,9 @@ func main() { }) g := gin.Default() - g.POST("/webhook/event", webhookEventHandle) + g.POST("/webhook/event", func(context *gin.Context) { + eventhttp.Handle(conf, context.Request, context.Writer) + }) err := g.Run(":8089") if err != nil { fmt.Println(err)