145 lines
6.0 KiB
Go
145 lines
6.0 KiB
Go
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
|
|
//
|
|
// Source: todo/v1/todo.proto
|
|
|
|
package todov1connect
|
|
|
|
import (
|
|
connect "connectrpc.com/connect"
|
|
context "context"
|
|
errors "errors"
|
|
v1 "git.kocoder.xyz/kocoded/vt/gen/todo/v1"
|
|
http "net/http"
|
|
strings "strings"
|
|
)
|
|
|
|
// This is a compile-time assertion to ensure that this generated file and the connect package are
|
|
// compatible. If you get a compiler error that this constant is not defined, this code was
|
|
// generated with a version of connect newer than the one compiled into your binary. You can fix the
|
|
// problem by either regenerating this code with an older version of connect or updating the connect
|
|
// version compiled into your binary.
|
|
const _ = connect.IsAtLeastVersion1_13_0
|
|
|
|
const (
|
|
// TodoServiceName is the fully-qualified name of the TodoService service.
|
|
TodoServiceName = "todo.v1.TodoService"
|
|
)
|
|
|
|
// These constants are the fully-qualified names of the RPCs defined in this package. They're
|
|
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
|
|
//
|
|
// Note that these are different from the fully-qualified method names used by
|
|
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
|
|
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
|
|
// period.
|
|
const (
|
|
// TodoServiceGetTodoProcedure is the fully-qualified name of the TodoService's GetTodo RPC.
|
|
TodoServiceGetTodoProcedure = "/todo.v1.TodoService/GetTodo"
|
|
// TodoServiceListTodosProcedure is the fully-qualified name of the TodoService's ListTodos RPC.
|
|
TodoServiceListTodosProcedure = "/todo.v1.TodoService/ListTodos"
|
|
)
|
|
|
|
// TodoServiceClient is a client for the todo.v1.TodoService service.
|
|
type TodoServiceClient interface {
|
|
GetTodo(context.Context, *v1.GetTodosRequest) (*v1.GetTodosResponse, error)
|
|
ListTodos(context.Context, *v1.ListTodosRequest) (*v1.ListTodosResponse, error)
|
|
}
|
|
|
|
// NewTodoServiceClient constructs a client for the todo.v1.TodoService service. By default, it uses
|
|
// the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and sends
|
|
// uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or
|
|
// connect.WithGRPCWeb() options.
|
|
//
|
|
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
|
|
// http://api.acme.com or https://acme.com/grpc).
|
|
func NewTodoServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TodoServiceClient {
|
|
baseURL = strings.TrimRight(baseURL, "/")
|
|
todoServiceMethods := v1.File_todo_v1_todo_proto.Services().ByName("TodoService").Methods()
|
|
return &todoServiceClient{
|
|
getTodo: connect.NewClient[v1.GetTodosRequest, v1.GetTodosResponse](
|
|
httpClient,
|
|
baseURL+TodoServiceGetTodoProcedure,
|
|
connect.WithSchema(todoServiceMethods.ByName("GetTodo")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
listTodos: connect.NewClient[v1.ListTodosRequest, v1.ListTodosResponse](
|
|
httpClient,
|
|
baseURL+TodoServiceListTodosProcedure,
|
|
connect.WithSchema(todoServiceMethods.ByName("ListTodos")),
|
|
connect.WithClientOptions(opts...),
|
|
),
|
|
}
|
|
}
|
|
|
|
// todoServiceClient implements TodoServiceClient.
|
|
type todoServiceClient struct {
|
|
getTodo *connect.Client[v1.GetTodosRequest, v1.GetTodosResponse]
|
|
listTodos *connect.Client[v1.ListTodosRequest, v1.ListTodosResponse]
|
|
}
|
|
|
|
// GetTodo calls todo.v1.TodoService.GetTodo.
|
|
func (c *todoServiceClient) GetTodo(ctx context.Context, req *v1.GetTodosRequest) (*v1.GetTodosResponse, error) {
|
|
response, err := c.getTodo.CallUnary(ctx, connect.NewRequest(req))
|
|
if response != nil {
|
|
return response.Msg, err
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
// ListTodos calls todo.v1.TodoService.ListTodos.
|
|
func (c *todoServiceClient) ListTodos(ctx context.Context, req *v1.ListTodosRequest) (*v1.ListTodosResponse, error) {
|
|
response, err := c.listTodos.CallUnary(ctx, connect.NewRequest(req))
|
|
if response != nil {
|
|
return response.Msg, err
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
// TodoServiceHandler is an implementation of the todo.v1.TodoService service.
|
|
type TodoServiceHandler interface {
|
|
GetTodo(context.Context, *v1.GetTodosRequest) (*v1.GetTodosResponse, error)
|
|
ListTodos(context.Context, *v1.ListTodosRequest) (*v1.ListTodosResponse, error)
|
|
}
|
|
|
|
// NewTodoServiceHandler builds an HTTP handler from the service implementation. It returns the path
|
|
// on which to mount the handler and the handler itself.
|
|
//
|
|
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
|
|
// and JSON codecs. They also support gzip compression.
|
|
func NewTodoServiceHandler(svc TodoServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
|
|
todoServiceMethods := v1.File_todo_v1_todo_proto.Services().ByName("TodoService").Methods()
|
|
todoServiceGetTodoHandler := connect.NewUnaryHandlerSimple(
|
|
TodoServiceGetTodoProcedure,
|
|
svc.GetTodo,
|
|
connect.WithSchema(todoServiceMethods.ByName("GetTodo")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
todoServiceListTodosHandler := connect.NewUnaryHandlerSimple(
|
|
TodoServiceListTodosProcedure,
|
|
svc.ListTodos,
|
|
connect.WithSchema(todoServiceMethods.ByName("ListTodos")),
|
|
connect.WithHandlerOptions(opts...),
|
|
)
|
|
return "/todo.v1.TodoService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case TodoServiceGetTodoProcedure:
|
|
todoServiceGetTodoHandler.ServeHTTP(w, r)
|
|
case TodoServiceListTodosProcedure:
|
|
todoServiceListTodosHandler.ServeHTTP(w, r)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
}
|
|
|
|
// UnimplementedTodoServiceHandler returns CodeUnimplemented from all methods.
|
|
type UnimplementedTodoServiceHandler struct{}
|
|
|
|
func (UnimplementedTodoServiceHandler) GetTodo(context.Context, *v1.GetTodosRequest) (*v1.GetTodosResponse, error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("todo.v1.TodoService.GetTodo is not implemented"))
|
|
}
|
|
|
|
func (UnimplementedTodoServiceHandler) ListTodos(context.Context, *v1.ListTodosRequest) (*v1.ListTodosResponse, error) {
|
|
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("todo.v1.TodoService.ListTodos is not implemented"))
|
|
}
|