| // Code generated by mobyextgen. DO NOT EDIT. | |
| package protogen | |
| import ( | |
| context "context" | |
| extensions "github.com/moby/extensions" | |
| clientpoint "github.com/moby/extensions/clientpoint" | |
| serverpoint "github.com/moby/extensions/serverpoint" | |
| daemonconfigv0 "github.com/moby/moby/v2/extpoints/daemonconfig/v0" | |
| grpc "google.golang.org/grpc" | |
| ) | |
| // serviceName is the point's fully-qualified gRPC service name. | |
| const serviceName = "org.mobyproject.extension.daemon.config.v0.DaemonConfig" | |
| const ( | |
| methodGet = "/" + serviceName + "/Get" | |
| ) | |
| // DaemonConfigServer is the server side of the point's gRPC service. It is the | |
| // proto-level shape of the point, not the point's Go interface: a contract | |
| // method returning a bare error returns an empty response message here. | |
| type DaemonConfigServer interface { | |
| Get(context.Context, *GetRequest) (*GetResponse, error) | |
| } | |
| // serviceDesc describes the point's gRPC service to a server. HandlerType is | |
| // what a registrar type-checks an implementation against, so registering the | |
| // wrong provider for this point is caught at registration. | |
| var serviceDesc = grpc.ServiceDesc{ | |
| ServiceName: serviceName, | |
| HandlerType: (*DaemonConfigServer)(nil), | |
| Metadata: "extpoints/daemonconfig/v0/daemon_config.proto", | |
| Methods: []grpc.MethodDesc{ | |
| {MethodName: "Get", Handler: handleGet}, | |
| }, | |
| } | |
| func handleGet(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) { | |
| in := new(GetRequest) | |
| if err := dec(in); err != nil { | |
| return nil, err | |
| } | |
| if interceptor == nil { | |
| return srv.(DaemonConfigServer).Get(ctx, in) | |
| } | |
| info := &grpc.UnaryServerInfo{Server: srv, FullMethod: methodGet} | |
| return interceptor(ctx, in, info, func(ctx context.Context, req any) (any, error) { | |
| return srv.(DaemonConfigServer).Get(ctx, req.(*GetRequest)) | |
| }) | |
| } | |
| // DaemonConfigClient calls the point's gRPC service. It is exported so a client | |
| // outside the framework - one calling a service an extension publishes on the | |
| // API socket - can reach it with a plain gRPC client. | |
| type DaemonConfigClient interface { | |
| Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) | |
| } | |
| // NewDaemonConfigClient returns a client for the point's gRPC service on cc. | |
| func NewDaemonConfigClient(cc grpc.ClientConnInterface) DaemonConfigClient { | |
| return &serviceClient{cc: cc} | |
| } | |
| type serviceClient struct{ cc grpc.ClientConnInterface } | |
| func (c *serviceClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { | |
| out := new(GetResponse) | |
| if err := c.cc.Invoke(ctx, methodGet, in, out, append([]grpc.CallOption{grpc.StaticMethod()}, opts...)...); err != nil { | |
| return nil, err | |
| } | |
| return out, nil | |
| } | |
| // ServerPoint serves the DaemonConfig point: it registers the point's gRPC service for | |
| // a provider with an SDK server. A binary passes it to (*sdk.Server).Register. | |
| var ServerPoint = serverpoint.Registration{ | |
| Point: daemonconfigv0.Point.ID(), | |
| Register: func(r grpc.ServiceRegistrar, impl any) { | |
| r.RegisterService(&serviceDesc, &grpcServer{impl: impl.(daemonconfigv0.DaemonConfig)}) | |
| }, | |
| } | |
| // ClientProvider builds a broker provider for the DaemonConfig point from an | |
| // out-of-process gRPC connection. | |
| func ClientProvider(conn grpc.ClientConnInterface) extensions.Provider { | |
| return daemonconfigv0.Point.Provide(NewClient(conn)) | |
| } | |
| // ClientPoint registers ClientProvider for the DaemonConfig point with a host. | |
| // Single carries the contract's cardinality: the point admits one provider. | |
| var ClientPoint = clientpoint.Registration{Point: daemonconfigv0.Point.ID(), Provider: ClientProvider, Single: true} | |
| // NewClient returns a daemonconfigv0.DaemonConfig that calls the DaemonConfig point over conn. | |
| func NewClient(conn grpc.ClientConnInterface) daemonconfigv0.DaemonConfig { | |
| return &grpcClient{client: NewDaemonConfigClient(conn)} | |
| } | |
| // grpcServer serves an implementation of the contract's Go interface. | |
| type grpcServer struct { | |
| impl daemonconfigv0.DaemonConfig | |
| } | |
| func (s *grpcServer) Get(ctx context.Context, req *GetRequest) (*GetResponse, error) { | |
| resp, err := s.impl.Get(ctx, getRequestFromProto(req)) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return getResponseToProto(resp), nil | |
| } | |
| type grpcClient struct { | |
| client DaemonConfigClient | |
| } | |
| func (c *grpcClient) Get(ctx context.Context, req *daemonconfigv0.GetRequest) (*daemonconfigv0.GetResponse, error) { | |
| resp, err := c.client.Get(ctx, getRequestToProto(req)) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return getResponseFromProto(resp), nil | |
| } | |
| func getRequestToProto(in *daemonconfigv0.GetRequest) *GetRequest { | |
| if in == nil { | |
| return nil | |
| } | |
| out := &GetRequest{} | |
| return out | |
| } | |
| func getRequestFromProto(in *GetRequest) *daemonconfigv0.GetRequest { | |
| if in == nil { | |
| return nil | |
| } | |
| out := &daemonconfigv0.GetRequest{} | |
| return out | |
| } | |
| func getResponseToProto(in *daemonconfigv0.GetResponse) *GetResponse { | |
| if in == nil { | |
| return nil | |
| } | |
| out := &GetResponse{} | |
| out.RootDir = in.RootDir | |
| return out | |
| } | |
| func getResponseFromProto(in *GetResponse) *daemonconfigv0.GetResponse { | |
| if in == nil { | |
| return nil | |
| } | |
| out := &daemonconfigv0.GetResponse{} | |
| out.RootDir = in.GetRootDir() | |
| return out | |
| } |