github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/protobuf/proto-go/cp/pb/protocol.http.pb.go (about)

     1  // Code generated by protoc-gen-go-http. DO NOT EDIT.
     2  // Source: protocol.proto
     3  
     4  package pb
     5  
     6  import (
     7  	context "context"
     8  	http1 "net/http"
     9  
    10  	transport "github.com/erda-project/erda-infra/pkg/transport"
    11  	http "github.com/erda-project/erda-infra/pkg/transport/http"
    12  	urlenc "github.com/erda-project/erda-infra/pkg/urlenc"
    13  )
    14  
    15  // This is a compile-time assertion to ensure that this generated file
    16  // is compatible with the "github.com/erda-project/erda-infra/pkg/transport/http" package it is being compiled against.
    17  const _ = http.SupportPackageIsVersion1
    18  
    19  // CPServiceHandler is the server API for CPService service.
    20  type CPServiceHandler interface {
    21  	// POST /api/component-protocol/actions/render
    22  	Render(context.Context, *RenderRequest) (*RenderResponse, error)
    23  }
    24  
    25  // RegisterCPServiceHandler register CPServiceHandler to http.Router.
    26  func RegisterCPServiceHandler(r http.Router, srv CPServiceHandler, opts ...http.HandleOption) {
    27  	h := http.DefaultHandleOptions()
    28  	for _, op := range opts {
    29  		op(h)
    30  	}
    31  	encodeFunc := func(fn func(http1.ResponseWriter, *http1.Request) (interface{}, error)) http.HandlerFunc {
    32  		handler := func(w http1.ResponseWriter, r *http1.Request) {
    33  			out, err := fn(w, r)
    34  			if err != nil {
    35  				h.Error(w, r, err)
    36  				return
    37  			}
    38  			if err := h.Encode(w, r, out); err != nil {
    39  				h.Error(w, r, err)
    40  			}
    41  		}
    42  		if h.HTTPInterceptor != nil {
    43  			handler = h.HTTPInterceptor(handler)
    44  		}
    45  		return handler
    46  	}
    47  
    48  	add_Render := func(method, path string, fn func(context.Context, *RenderRequest) (*RenderResponse, error)) {
    49  		handler := func(ctx context.Context, req interface{}) (interface{}, error) {
    50  			return fn(ctx, req.(*RenderRequest))
    51  		}
    52  		var Render_info transport.ServiceInfo
    53  		if h.Interceptor != nil {
    54  			Render_info = transport.NewServiceInfo("erda.cp.CPService", "Render", srv)
    55  			handler = h.Interceptor(handler)
    56  		}
    57  		r.Add(method, path, encodeFunc(
    58  			func(w http1.ResponseWriter, r *http1.Request) (interface{}, error) {
    59  				ctx := http.WithRequest(r.Context(), r)
    60  				ctx = transport.WithHTTPHeaderForServer(ctx, r.Header)
    61  				if h.Interceptor != nil {
    62  					ctx = context.WithValue(ctx, transport.ServiceInfoContextKey, Render_info)
    63  				}
    64  				r = r.WithContext(ctx)
    65  				var in RenderRequest
    66  				if err := h.Decode(r, &in); err != nil {
    67  					return nil, err
    68  				}
    69  				var input interface{} = &in
    70  				if u, ok := (input).(urlenc.URLValuesUnmarshaler); ok {
    71  					if err := u.UnmarshalURLValues("", r.URL.Query()); err != nil {
    72  						return nil, err
    73  					}
    74  				}
    75  				out, err := handler(ctx, &in)
    76  				if err != nil {
    77  					return out, err
    78  				}
    79  				return out, nil
    80  			}),
    81  		)
    82  	}
    83  
    84  	add_Render("POST", "/api/component-protocol/actions/render", srv.Render)
    85  }