chainUnaryServerInterceptors chains all unary server interceptors into one.
(s *Server)
| 1223 | |
| 1224 | // chainUnaryServerInterceptors chains all unary server interceptors into one. |
| 1225 | func chainUnaryServerInterceptors(s *Server) { |
| 1226 | // Prepend opts.unaryInt to the chaining interceptors if it exists, since unaryInt will |
| 1227 | // be executed before any other chained interceptors. |
| 1228 | interceptors := s.opts.chainUnaryInts |
| 1229 | if s.opts.unaryInt != nil { |
| 1230 | interceptors = append([]UnaryServerInterceptor{s.opts.unaryInt}, s.opts.chainUnaryInts...) |
| 1231 | } |
| 1232 | |
| 1233 | var chainedInt UnaryServerInterceptor |
| 1234 | if len(interceptors) == 0 { |
| 1235 | chainedInt = nil |
| 1236 | } else if len(interceptors) == 1 { |
| 1237 | chainedInt = interceptors[0] |
| 1238 | } else { |
| 1239 | chainedInt = chainUnaryInterceptors(interceptors) |
| 1240 | } |
| 1241 | |
| 1242 | s.opts.unaryInt = chainedInt |
| 1243 | } |
| 1244 | |
| 1245 | func chainUnaryInterceptors(interceptors []UnaryServerInterceptor) UnaryServerInterceptor { |
| 1246 | return func(ctx context.Context, req any, info *UnaryServerInfo, handler UnaryHandler) (any, error) { |
no test coverage detected