Unverified Commit 784fcbb6 authored by Ryo's avatar Ryo Committed by GitHub

feat: add panic recovery middleware for grpc and echo server (#3459)

parent 1ccfa81c
...@@ -14,6 +14,7 @@ require ( ...@@ -14,6 +14,7 @@ require (
github.com/google/cel-go v0.20.1 github.com/google/cel-go v0.20.1
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
github.com/gorilla/feeds v1.1.2 github.com/gorilla/feeds v1.1.2
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/improbable-eng/grpc-web v0.15.0 github.com/improbable-eng/grpc-web v0.15.0
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
......
This diff is collapsed.
...@@ -10,10 +10,12 @@ import ( ...@@ -10,10 +10,12 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/soheilhy/cmux" "github.com/soheilhy/cmux"
"google.golang.org/grpc" "google.golang.org/grpc"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
storepb "github.com/usememos/memos/proto/gen/store" storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/server/profile" "github.com/usememos/memos/server/profile"
apiv1 "github.com/usememos/memos/server/router/api/v1" apiv1 "github.com/usememos/memos/server/router/api/v1"
...@@ -43,6 +45,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store ...@@ -43,6 +45,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
echoServer.Debug = true echoServer.Debug = true
echoServer.HideBanner = true echoServer.HideBanner = true
echoServer.HidePort = true echoServer.HidePort = true
echoServer.Use(middleware.Recover())
s.echoServer = echoServer s.echoServer = echoServer
workspaceBasicSetting, err := s.getOrUpsertWorkspaceBasicSetting(ctx) workspaceBasicSetting, err := s.getOrUpsertWorkspaceBasicSetting(ctx)
...@@ -74,6 +77,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store ...@@ -74,6 +77,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
grpc.MaxRecvMsgSize(100*1024*1024), grpc.MaxRecvMsgSize(100*1024*1024),
grpc.ChainUnaryInterceptor( grpc.ChainUnaryInterceptor(
apiv1.NewLoggerInterceptor().LoggerInterceptor, apiv1.NewLoggerInterceptor().LoggerInterceptor,
grpc_recovery.UnaryServerInterceptor(),
apiv1.NewGRPCAuthInterceptor(store, secret).AuthenticationInterceptor, apiv1.NewGRPCAuthInterceptor(store, secret).AuthenticationInterceptor,
)) ))
s.grpcServer = grpcServer s.grpcServer = grpcServer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment