github.com/grafana/pyroscope@v1.18.0/pkg/util/httpgrpc/httpgrpcconnect/httpgrpc.connect.go (about) 1 // Code generated by protoc-gen-connect-go. DO NOT EDIT. 2 // 3 // Source: util/httpgrpc/httpgrpc.proto 4 5 package httpgrpcconnect 6 7 import ( 8 connect "connectrpc.com/connect" 9 context "context" 10 errors "errors" 11 httpgrpc "github.com/grafana/pyroscope/pkg/util/httpgrpc" 12 http "net/http" 13 strings "strings" 14 ) 15 16 // This is a compile-time assertion to ensure that this generated file and the connect package are 17 // compatible. If you get a compiler error that this constant is not defined, this code was 18 // generated with a version of connect newer than the one compiled into your binary. You can fix the 19 // problem by either regenerating this code with an older version of connect or updating the connect 20 // version compiled into your binary. 21 const _ = connect.IsAtLeastVersion1_13_0 22 23 const ( 24 // HTTPName is the fully-qualified name of the HTTP service. 25 HTTPName = "httpgrpc.HTTP" 26 ) 27 28 // These constants are the fully-qualified names of the RPCs defined in this package. They're 29 // exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route. 30 // 31 // Note that these are different from the fully-qualified method names used by 32 // google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to 33 // reflection-formatted method names, remove the leading slash and convert the remaining slash to a 34 // period. 35 const ( 36 // HTTPHandleProcedure is the fully-qualified name of the HTTP's Handle RPC. 37 HTTPHandleProcedure = "/httpgrpc.HTTP/Handle" 38 ) 39 40 // HTTPClient is a client for the httpgrpc.HTTP service. 41 type HTTPClient interface { 42 Handle(context.Context, *connect.Request[httpgrpc.HTTPRequest]) (*connect.Response[httpgrpc.HTTPResponse], error) 43 } 44 45 // NewHTTPClient constructs a client for the httpgrpc.HTTP service. By default, it uses the Connect 46 // protocol with the binary Protobuf Codec, asks for gzipped responses, and sends uncompressed 47 // requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or 48 // connect.WithGRPCWeb() options. 49 // 50 // The URL supplied here should be the base URL for the Connect or gRPC server (for example, 51 // http://api.acme.com or https://acme.com/grpc). 52 func NewHTTPClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) HTTPClient { 53 baseURL = strings.TrimRight(baseURL, "/") 54 hTTPMethods := httpgrpc.File_util_httpgrpc_httpgrpc_proto.Services().ByName("HTTP").Methods() 55 return &hTTPClient{ 56 handle: connect.NewClient[httpgrpc.HTTPRequest, httpgrpc.HTTPResponse]( 57 httpClient, 58 baseURL+HTTPHandleProcedure, 59 connect.WithSchema(hTTPMethods.ByName("Handle")), 60 connect.WithClientOptions(opts...), 61 ), 62 } 63 } 64 65 // hTTPClient implements HTTPClient. 66 type hTTPClient struct { 67 handle *connect.Client[httpgrpc.HTTPRequest, httpgrpc.HTTPResponse] 68 } 69 70 // Handle calls httpgrpc.HTTP.Handle. 71 func (c *hTTPClient) Handle(ctx context.Context, req *connect.Request[httpgrpc.HTTPRequest]) (*connect.Response[httpgrpc.HTTPResponse], error) { 72 return c.handle.CallUnary(ctx, req) 73 } 74 75 // HTTPHandler is an implementation of the httpgrpc.HTTP service. 76 type HTTPHandler interface { 77 Handle(context.Context, *connect.Request[httpgrpc.HTTPRequest]) (*connect.Response[httpgrpc.HTTPResponse], error) 78 } 79 80 // NewHTTPHandler builds an HTTP handler from the service implementation. It returns the path on 81 // which to mount the handler and the handler itself. 82 // 83 // By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf 84 // and JSON codecs. They also support gzip compression. 85 func NewHTTPHandler(svc HTTPHandler, opts ...connect.HandlerOption) (string, http.Handler) { 86 hTTPMethods := httpgrpc.File_util_httpgrpc_httpgrpc_proto.Services().ByName("HTTP").Methods() 87 hTTPHandleHandler := connect.NewUnaryHandler( 88 HTTPHandleProcedure, 89 svc.Handle, 90 connect.WithSchema(hTTPMethods.ByName("Handle")), 91 connect.WithHandlerOptions(opts...), 92 ) 93 return "/httpgrpc.HTTP/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 94 switch r.URL.Path { 95 case HTTPHandleProcedure: 96 hTTPHandleHandler.ServeHTTP(w, r) 97 default: 98 http.NotFound(w, r) 99 } 100 }) 101 } 102 103 // UnimplementedHTTPHandler returns CodeUnimplemented from all methods. 104 type UnimplementedHTTPHandler struct{} 105 106 func (UnimplementedHTTPHandler) Handle(context.Context, *connect.Request[httpgrpc.HTTPRequest]) (*connect.Response[httpgrpc.HTTPResponse], error) { 107 return nil, connect.NewError(connect.CodeUnimplemented, errors.New("httpgrpc.HTTP.Handle is not implemented")) 108 }