Documentation ¶
Overview ¶
Package v1 is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
Index ¶
- Constants
- Variables
- func RegisterGreeterServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
- func RegisterGreeterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GreeterServiceClient) error
- func RegisterGreeterServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, ...) (err error)
- func RegisterGreeterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server GreeterServiceServer) error
- func RegisterGreeterServiceServer(s grpc.ServiceRegistrar, srv GreeterServiceServer)
- func WriteError(resp http.ResponseWriter, err error)
- type GreeterService
- type GreeterServiceClient
- type GreeterServiceServer
- type HTTPClient
- type HelloRequest
- type HelloResponse
- type SignRequest
- type SignResponse
- type TwirpServer
- type UnimplementedGreeterServiceServer
- type UnsafeGreeterServiceServer
Constants ¶
const ( GreeterService_Hello_FullMethodName = "/api.rpc.v1.GreeterService/Hello" GreeterService_Sign_FullMethodName = "/api.rpc.v1.GreeterService/Sign" )
const GreeterServicePathPrefix = "/twirp/api.rpc.v1.GreeterService/"
GreeterServicePathPrefix is a convenience constant that may identify URL paths. Should be used with caution, it only matches routes generated by Twirp Go clients, with the default "/twirp" prefix and default CamelCase service and method names. More info: https://twitchtv.github.io/twirp/docs/routing.html
Variables ¶
var File_v1_service_proto protoreflect.FileDescriptor
var GreeterService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "api.rpc.v1.GreeterService", HandlerType: (*GreeterServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Hello", Handler: _GreeterService_Hello_Handler, }, { MethodName: "Sign", Handler: _GreeterService_Sign_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "v1/service.proto", }
GreeterService_ServiceDesc is the grpc.ServiceDesc for GreeterService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)
Functions ¶
func RegisterGreeterServiceHandler ¶
func RegisterGreeterServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
RegisterGreeterServiceHandler registers the http handlers for service GreeterService to "mux". The handlers forward requests to the grpc endpoint over "conn".
func RegisterGreeterServiceHandlerClient ¶
func RegisterGreeterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GreeterServiceClient) error
RegisterGreeterServiceHandlerClient registers the http handlers for service GreeterService to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "GreeterServiceClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "GreeterServiceClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "GreeterServiceClient" to call the correct interceptors.
func RegisterGreeterServiceHandlerFromEndpoint ¶
func RegisterGreeterServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)
RegisterGreeterServiceHandlerFromEndpoint is same as RegisterGreeterServiceHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterGreeterServiceHandlerServer ¶
func RegisterGreeterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server GreeterServiceServer) error
RegisterGreeterServiceHandlerServer registers the http handlers for service GreeterService to "mux". UnaryRPC :call GreeterServiceServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterGreeterServiceHandlerFromEndpoint instead.
func RegisterGreeterServiceServer ¶
func RegisterGreeterServiceServer(s grpc.ServiceRegistrar, srv GreeterServiceServer)
func WriteError ¶
func WriteError(resp http.ResponseWriter, err error)
WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)
Types ¶
type GreeterService ¶
type GreeterService interface { Hello(context.Context, *HelloRequest) (*HelloResponse, error) Sign(context.Context, *SignRequest) (*SignResponse, error) }
func NewGreeterServiceJSONClient ¶
func NewGreeterServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) GreeterService
NewGreeterServiceJSONClient creates a JSON client that implements the GreeterService interface. It communicates using JSON and can be configured with a custom HTTPClient.
func NewGreeterServiceProtobufClient ¶
func NewGreeterServiceProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) GreeterService
NewGreeterServiceProtobufClient creates a Protobuf client that implements the GreeterService interface. It communicates using Protobuf and can be configured with a custom HTTPClient.
type GreeterServiceClient ¶
type GreeterServiceClient interface { Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) Sign(ctx context.Context, in *SignRequest, opts ...grpc.CallOption) (*SignResponse, error) }
GreeterServiceClient is the client API for GreeterService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewGreeterServiceClient ¶
func NewGreeterServiceClient(cc grpc.ClientConnInterface) GreeterServiceClient
type GreeterServiceServer ¶
type GreeterServiceServer interface { Hello(context.Context, *HelloRequest) (*HelloResponse, error) Sign(context.Context, *SignRequest) (*SignResponse, error) // contains filtered or unexported methods }
GreeterServiceServer is the server API for GreeterService service. All implementations must embed UnimplementedGreeterServiceServer for forward compatibility
type HTTPClient ¶
HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/http).Client, which is sufficient for most users. Users can provide their own implementation for special retry policies.
HTTPClient implementations should not follow redirects. Redirects are automatically disabled if *(net/http).Client is passed to client constructors. See the withoutRedirects function in this file for more details.
type HelloRequest ¶
type HelloRequest struct { Subject string `protobuf:"bytes,1,opt,name=subject,proto3" json:"subject,omitempty"` // contains filtered or unexported fields }
func (*HelloRequest) Descriptor
deprecated
func (*HelloRequest) Descriptor() ([]byte, []int)
Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead.
func (*HelloRequest) GetSubject ¶
func (x *HelloRequest) GetSubject() string
func (*HelloRequest) ProtoMessage ¶
func (*HelloRequest) ProtoMessage()
func (*HelloRequest) ProtoReflect ¶
func (x *HelloRequest) ProtoReflect() protoreflect.Message
func (*HelloRequest) Reset ¶
func (x *HelloRequest) Reset()
func (*HelloRequest) String ¶
func (x *HelloRequest) String() string
type HelloResponse ¶
type HelloResponse struct { Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` // contains filtered or unexported fields }
func (*HelloResponse) Descriptor
deprecated
func (*HelloResponse) Descriptor() ([]byte, []int)
Deprecated: Use HelloResponse.ProtoReflect.Descriptor instead.
func (*HelloResponse) GetText ¶
func (x *HelloResponse) GetText() string
func (*HelloResponse) ProtoMessage ¶
func (*HelloResponse) ProtoMessage()
func (*HelloResponse) ProtoReflect ¶
func (x *HelloResponse) ProtoReflect() protoreflect.Message
func (*HelloResponse) Reset ¶
func (x *HelloResponse) Reset()
func (*HelloResponse) String ¶
func (x *HelloResponse) String() string
type SignRequest ¶
type SignRequest struct {
// contains filtered or unexported fields
}
func (*SignRequest) Descriptor
deprecated
func (*SignRequest) Descriptor() ([]byte, []int)
Deprecated: Use SignRequest.ProtoReflect.Descriptor instead.
func (*SignRequest) ProtoMessage ¶
func (*SignRequest) ProtoMessage()
func (*SignRequest) ProtoReflect ¶
func (x *SignRequest) ProtoReflect() protoreflect.Message
func (*SignRequest) Reset ¶
func (x *SignRequest) Reset()
func (*SignRequest) String ¶
func (x *SignRequest) String() string
type SignResponse ¶
type SignResponse struct { License []byte `protobuf:"bytes,1,opt,name=license,proto3" json:"license,omitempty"` // contains filtered or unexported fields }
func (*SignResponse) Descriptor
deprecated
func (*SignResponse) Descriptor() ([]byte, []int)
Deprecated: Use SignResponse.ProtoReflect.Descriptor instead.
func (*SignResponse) GetLicense ¶
func (x *SignResponse) GetLicense() []byte
func (*SignResponse) ProtoMessage ¶
func (*SignResponse) ProtoMessage()
func (*SignResponse) ProtoReflect ¶
func (x *SignResponse) ProtoReflect() protoreflect.Message
func (*SignResponse) Reset ¶
func (x *SignResponse) Reset()
func (*SignResponse) String ¶
func (x *SignResponse) String() string
type TwirpServer ¶
type TwirpServer interface { http.Handler // ServiceDescriptor returns gzipped bytes describing the .proto file that // this service was generated from. Once unzipped, the bytes can be // unmarshalled as a // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. // // The returned integer is the index of this particular service within that // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a // low-level field, expected to be used for reflection. ServiceDescriptor() ([]byte, int) // ProtocGenTwirpVersion is the semantic version string of the version of // twirp used to generate this file. ProtocGenTwirpVersion() string // PathPrefix returns the HTTP URL path prefix for all methods handled by this // service. This can be used with an HTTP mux to route Twirp requests. // The path prefix is in the form: "/<prefix>/<package>.<Service>/" // that is, everything in a Twirp route except for the <Method> at the end. PathPrefix() string }
TwirpServer is the interface generated server structs will support: they're HTTP handlers with additional methods for accessing metadata about the service. Those accessors are a low-level API for building reflection tools. Most people can think of TwirpServers as just http.Handlers.
func NewGreeterServiceServer ¶
func NewGreeterServiceServer(svc GreeterService, opts ...interface{}) TwirpServer
NewGreeterServiceServer builds a TwirpServer that can be used as an http.Handler to handle HTTP requests that are routed to the right method in the provided svc implementation. The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).
type UnimplementedGreeterServiceServer ¶
type UnimplementedGreeterServiceServer struct { }
UnimplementedGreeterServiceServer must be embedded to have forward compatible implementations.
func (UnimplementedGreeterServiceServer) Hello ¶
func (UnimplementedGreeterServiceServer) Hello(context.Context, *HelloRequest) (*HelloResponse, error)
func (UnimplementedGreeterServiceServer) Sign ¶
func (UnimplementedGreeterServiceServer) Sign(context.Context, *SignRequest) (*SignResponse, error)
type UnsafeGreeterServiceServer ¶
type UnsafeGreeterServiceServer interface {
// contains filtered or unexported methods
}
UnsafeGreeterServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to GreeterServiceServer will result in compilation errors.