...

Source file src/github.com/containerd/ttrpc/interceptor.go

Documentation: github.com/containerd/ttrpc

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package ttrpc
    18  
    19  import "context"
    20  
    21  // UnaryServerInfo provides information about the server request
    22  type UnaryServerInfo struct {
    23  	FullMethod string
    24  }
    25  
    26  // UnaryClientInfo provides information about the client request
    27  type UnaryClientInfo struct {
    28  	FullMethod string
    29  }
    30  
    31  // StreamServerInfo provides information about the server request
    32  type StreamServerInfo struct {
    33  	FullMethod      string
    34  	StreamingClient bool
    35  	StreamingServer bool
    36  }
    37  
    38  // Unmarshaler contains the server request data and allows it to be unmarshaled
    39  // into a concrete type
    40  type Unmarshaler func(interface{}) error
    41  
    42  // Invoker invokes the client's request and response from the ttrpc server
    43  type Invoker func(context.Context, *Request, *Response) error
    44  
    45  // UnaryServerInterceptor specifies the interceptor function for server request/response
    46  type UnaryServerInterceptor func(context.Context, Unmarshaler, *UnaryServerInfo, Method) (interface{}, error)
    47  
    48  // UnaryClientInterceptor specifies the interceptor function for client request/response
    49  type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error
    50  
    51  func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, _ *UnaryServerInfo, method Method) (interface{}, error) {
    52  	return method(ctx, unmarshal)
    53  }
    54  
    55  func defaultClientInterceptor(ctx context.Context, req *Request, resp *Response, _ *UnaryClientInfo, invoker Invoker) error {
    56  	return invoker(ctx, req, resp)
    57  }
    58  
    59  type StreamServerInterceptor func(context.Context, StreamServer, *StreamServerInfo, StreamHandler) (interface{}, error)
    60  
    61  func defaultStreamServerInterceptor(ctx context.Context, ss StreamServer, _ *StreamServerInfo, stream StreamHandler) (interface{}, error) {
    62  	return stream(ctx, ss)
    63  }
    64  
    65  type StreamClientInterceptor func(context.Context)
    66  

View as plain text