adapters

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package adapters provides infrastructure adapters for the notification feature.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCClient added in v0.6.0

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient implements ports.Sender by calling a remote notification service over gRPC. It demonstrates how a standalone process can consume a feature without importing its implementation — the gRPC counterpart of HTTPClient.

func NewGRPCClient added in v0.6.0

func NewGRPCClient(conn *googlegrpc.ClientConn) *GRPCClient

NewGRPCClient creates a remote notification client backed by conn. conn must not be nil; the caller owns dialing it (typically with googlegrpc.NewClient plus modulexgrpc.DialOptions(), as notification.GRPCRemoteModule does) and closing it during shutdown.

func (*GRPCClient) Send added in v0.6.0

func (c *GRPCClient) Send(ctx context.Context, message string) error

Send implements ports.Sender by forwarding the message to the remote gRPC service. Any error returned by the RPC is translated via modulexgrpc.TranslateError into one of that package's sentinel errors, so a caller can use errors.Is(err, modulexgrpc.ErrInvalidInput) instead of inspecting the gRPC status directly.

type GRPCServer added in v0.6.0

type GRPCServer struct {
	notificationpb.UnimplementedNotificationServer
	// contains filtered or unexported fields
}

GRPCServer exposes the notification service over gRPC. It keeps gRPC concerns (the generated request/response types) separate from business logic, mirroring HTTPServer's role for the HTTP transport.

GRPCServer returns the domain error from ports.Sender.Send unchanged; it does not convert it to a gRPC status itself. Consistent error-to-status mapping is applied once, centrally, by the grpc.UnaryServerErrorInterceptor configured on the *grpc.Server that hosts this service (see grpcErrorMapping in ../grpc_module.go) rather than repeated in every handler.

func NewGRPCServer added in v0.6.0

func NewGRPCServer(svc ports.Sender) *GRPCServer

NewGRPCServer creates a gRPC adapter for the notification service.

func (*GRPCServer) Send added in v0.6.0

Send implements notificationpb.NotificationServer by forwarding the request to the wrapped ports.Sender.

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient implements ports.Sender by calling a remote notification service over HTTP. It demonstrates how a standalone process can consume a feature without importing its implementation.

func NewHTTPClient

func NewHTTPClient(baseURL string, client *http.Client) (*HTTPClient, error)

NewHTTPClient creates a remote notification client.

baseURL must be a non-empty string. If client is nil, http.DefaultClient is used.

func (*HTTPClient) Send

func (c *HTTPClient) Send(ctx context.Context, message string) error

Send implements ports.Sender by forwarding the message to the remote service.

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields
}

HTTPServer exposes the notification service over HTTP. It keeps HTTP concerns (encoding, status codes) separate from business logic.

func NewHTTPServer

func NewHTTPServer(svc ports.Sender, logger *slog.Logger) *HTTPServer

NewHTTPServer creates an HTTP adapter for the notification service.

func (*HTTPServer) SendHandler

func (s *HTTPServer) SendHandler() http.HandlerFunc

SendHandler returns an http.HandlerFunc that forwards requests to the notification service.

type SendRequest

type SendRequest struct {
	Message string `json:"message"`
}

SendRequest is the JSON body accepted by the send endpoint.

type SendResponse

type SendResponse struct {
	Status string `json:"status"`
}

SendResponse is the JSON body returned by the send endpoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL