feat(api): add composite ogen handler for incremental operations
This commit is contained in:
1 parent
0f206bfc29
commit
b2f6e87bfe
6 files changed
+133
-6
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
)
|
||||
|
||||
// Handler is the composite implementation of the generated api.Handler.
|
||||
//
|
||||
// The embedded api.UnimplementedHandler keeps the backend compiling after the
|
||||
// contract gains an operation that has no business implementation yet. Such an
|
||||
// operation returns ht.ErrNotImplemented without side effects. The generated
|
||||
// server passes that error to its configured ErrorHandler, and the default
|
||||
// ogenerrors.DefaultErrorHandler maps it to HTTP 501. When the contract defines
|
||||
// a default error response, the generated server still sends
|
||||
// ht.ErrNotImplemented to ErrorHandler before calling NewError. The embedded
|
||||
// NewError, however, returns a zero status code that the generated encoder
|
||||
// sends as HTTP 200, so the composite must then define NewError explicitly.
|
||||
// That NewError must answer *ogenerrors.SecurityError with 401 or 403, which
|
||||
// the generated server passes to it directly, and answer every other error
|
||||
// with 500 and a sanitized message, never err.Error() of an internal error.
|
||||
// Errors of the generated status-code error type (*<Schema>StatusCode) are
|
||||
// encoded before NewError is called, so it does not need to handle them.
|
||||
//
|
||||
// Each implemented operation gets an explicit method here that delegates to
|
||||
// the handler owning it. Each implemented operation also gets a router test
|
||||
// through v1.NewHandler that asserts a non-501 response, because renaming an
|
||||
// operationId would otherwise silently fall back to the embedded 501 method.
|
||||
type Handler struct {
|
||||
api.UnimplementedHandler
|
||||
|
||||
health *HealthHandler
|
||||
}
|
||||
|
||||
var _ api.Handler = (*Handler)(nil)
|
||||
|
||||
func NewHandler(health *HealthHandler) *Handler {
|
||||
return &Handler{health: health}
|
||||
}
|
||||
|
||||
func (handler *Handler) GetHealthz(ctx context.Context) (*api.HealthResponse, error) {
|
||||
return handler.health.GetHealthz(ctx)
|
||||
}
|
||||
Reference in new issue
Block a user