Server-Side-Implementation

This commit is contained in:
2025-12-29 16:42:49 +01:00
commit c9d0322177
20 changed files with 1539 additions and 0 deletions

View File

@ -0,0 +1,180 @@
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: portforwarding/portforwarding.proto
package portforwardingv1connect
import (
connect "connectrpc.com/connect"
context "context"
errors "errors"
portforwarding "git.kocoder.xyz/kocoder/portforwarder/gen/portforwarding"
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 (
// PortForwardingServiceName is the fully-qualified name of the PortForwardingService service.
PortForwardingServiceName = "portforwarding.v1.PortForwardingService"
)
// 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 (
// PortForwardingServiceListPortforwardingsProcedure is the fully-qualified name of the
// PortForwardingService's ListPortforwardings RPC.
PortForwardingServiceListPortforwardingsProcedure = "/portforwarding.v1.PortForwardingService/ListPortforwardings"
// PortForwardingServiceCreatePortforwardingProcedure is the fully-qualified name of the
// PortForwardingService's CreatePortforwarding RPC.
PortForwardingServiceCreatePortforwardingProcedure = "/portforwarding.v1.PortForwardingService/CreatePortforwarding"
// PortForwardingServiceDeletePortforwardingProcedure is the fully-qualified name of the
// PortForwardingService's DeletePortforwarding RPC.
PortForwardingServiceDeletePortforwardingProcedure = "/portforwarding.v1.PortForwardingService/DeletePortforwarding"
)
// PortForwardingServiceClient is a client for the portforwarding.v1.PortForwardingService service.
type PortForwardingServiceClient interface {
ListPortforwardings(context.Context, *portforwarding.ListPortforwardingsRequest) (*portforwarding.ListPortforwardingsResponse, error)
CreatePortforwarding(context.Context, *portforwarding.CreatePortforwardingRequest) (*portforwarding.CreatePortforwardingResponse, error)
DeletePortforwarding(context.Context, *portforwarding.DeletePortforwardingRequest) (*portforwarding.DeletePortforwardingResponse, error)
}
// NewPortForwardingServiceClient constructs a client for the
// portforwarding.v1.PortForwardingService 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 NewPortForwardingServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PortForwardingServiceClient {
baseURL = strings.TrimRight(baseURL, "/")
portForwardingServiceMethods := portforwarding.File_portforwarding_portforwarding_proto.Services().ByName("PortForwardingService").Methods()
return &portForwardingServiceClient{
listPortforwardings: connect.NewClient[portforwarding.ListPortforwardingsRequest, portforwarding.ListPortforwardingsResponse](
httpClient,
baseURL+PortForwardingServiceListPortforwardingsProcedure,
connect.WithSchema(portForwardingServiceMethods.ByName("ListPortforwardings")),
connect.WithClientOptions(opts...),
),
createPortforwarding: connect.NewClient[portforwarding.CreatePortforwardingRequest, portforwarding.CreatePortforwardingResponse](
httpClient,
baseURL+PortForwardingServiceCreatePortforwardingProcedure,
connect.WithSchema(portForwardingServiceMethods.ByName("CreatePortforwarding")),
connect.WithClientOptions(opts...),
),
deletePortforwarding: connect.NewClient[portforwarding.DeletePortforwardingRequest, portforwarding.DeletePortforwardingResponse](
httpClient,
baseURL+PortForwardingServiceDeletePortforwardingProcedure,
connect.WithSchema(portForwardingServiceMethods.ByName("DeletePortforwarding")),
connect.WithClientOptions(opts...),
),
}
}
// portForwardingServiceClient implements PortForwardingServiceClient.
type portForwardingServiceClient struct {
listPortforwardings *connect.Client[portforwarding.ListPortforwardingsRequest, portforwarding.ListPortforwardingsResponse]
createPortforwarding *connect.Client[portforwarding.CreatePortforwardingRequest, portforwarding.CreatePortforwardingResponse]
deletePortforwarding *connect.Client[portforwarding.DeletePortforwardingRequest, portforwarding.DeletePortforwardingResponse]
}
// ListPortforwardings calls portforwarding.v1.PortForwardingService.ListPortforwardings.
func (c *portForwardingServiceClient) ListPortforwardings(ctx context.Context, req *portforwarding.ListPortforwardingsRequest) (*portforwarding.ListPortforwardingsResponse, error) {
response, err := c.listPortforwardings.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// CreatePortforwarding calls portforwarding.v1.PortForwardingService.CreatePortforwarding.
func (c *portForwardingServiceClient) CreatePortforwarding(ctx context.Context, req *portforwarding.CreatePortforwardingRequest) (*portforwarding.CreatePortforwardingResponse, error) {
response, err := c.createPortforwarding.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// DeletePortforwarding calls portforwarding.v1.PortForwardingService.DeletePortforwarding.
func (c *portForwardingServiceClient) DeletePortforwarding(ctx context.Context, req *portforwarding.DeletePortforwardingRequest) (*portforwarding.DeletePortforwardingResponse, error) {
response, err := c.deletePortforwarding.CallUnary(ctx, connect.NewRequest(req))
if response != nil {
return response.Msg, err
}
return nil, err
}
// PortForwardingServiceHandler is an implementation of the portforwarding.v1.PortForwardingService
// service.
type PortForwardingServiceHandler interface {
ListPortforwardings(context.Context, *portforwarding.ListPortforwardingsRequest) (*portforwarding.ListPortforwardingsResponse, error)
CreatePortforwarding(context.Context, *portforwarding.CreatePortforwardingRequest) (*portforwarding.CreatePortforwardingResponse, error)
DeletePortforwarding(context.Context, *portforwarding.DeletePortforwardingRequest) (*portforwarding.DeletePortforwardingResponse, error)
}
// NewPortForwardingServiceHandler 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 NewPortForwardingServiceHandler(svc PortForwardingServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
portForwardingServiceMethods := portforwarding.File_portforwarding_portforwarding_proto.Services().ByName("PortForwardingService").Methods()
portForwardingServiceListPortforwardingsHandler := connect.NewUnaryHandlerSimple(
PortForwardingServiceListPortforwardingsProcedure,
svc.ListPortforwardings,
connect.WithSchema(portForwardingServiceMethods.ByName("ListPortforwardings")),
connect.WithHandlerOptions(opts...),
)
portForwardingServiceCreatePortforwardingHandler := connect.NewUnaryHandlerSimple(
PortForwardingServiceCreatePortforwardingProcedure,
svc.CreatePortforwarding,
connect.WithSchema(portForwardingServiceMethods.ByName("CreatePortforwarding")),
connect.WithHandlerOptions(opts...),
)
portForwardingServiceDeletePortforwardingHandler := connect.NewUnaryHandlerSimple(
PortForwardingServiceDeletePortforwardingProcedure,
svc.DeletePortforwarding,
connect.WithSchema(portForwardingServiceMethods.ByName("DeletePortforwarding")),
connect.WithHandlerOptions(opts...),
)
return "/portforwarding.v1.PortForwardingService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case PortForwardingServiceListPortforwardingsProcedure:
portForwardingServiceListPortforwardingsHandler.ServeHTTP(w, r)
case PortForwardingServiceCreatePortforwardingProcedure:
portForwardingServiceCreatePortforwardingHandler.ServeHTTP(w, r)
case PortForwardingServiceDeletePortforwardingProcedure:
portForwardingServiceDeletePortforwardingHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})
}
// UnimplementedPortForwardingServiceHandler returns CodeUnimplemented from all methods.
type UnimplementedPortForwardingServiceHandler struct{}
func (UnimplementedPortForwardingServiceHandler) ListPortforwardings(context.Context, *portforwarding.ListPortforwardingsRequest) (*portforwarding.ListPortforwardingsResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("portforwarding.v1.PortForwardingService.ListPortforwardings is not implemented"))
}
func (UnimplementedPortForwardingServiceHandler) CreatePortforwarding(context.Context, *portforwarding.CreatePortforwardingRequest) (*portforwarding.CreatePortforwardingResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("portforwarding.v1.PortForwardingService.CreatePortforwarding is not implemented"))
}
func (UnimplementedPortForwardingServiceHandler) DeletePortforwarding(context.Context, *portforwarding.DeletePortforwardingRequest) (*portforwarding.DeletePortforwardingResponse, error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("portforwarding.v1.PortForwardingService.DeletePortforwarding is not implemented"))
}