{"modulePath":"github.com/oapi-codegen/oapi-codegen-exp/experimental","version":"v0.0.0-20260413235603-d24950bd28cc","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package doorbadge\n\nPackage doorbadge provides an example of OpenAPI 3.1 webhooks. A door badge reader server generates random enter/exit events and notifies registered webhook listeners.\n\nYou can run the example by running these two commands in parallel:\n\n\tgo run ./server --port 8080\n\tgo run ./client --server http://localhost:8080\n\nYou can run multiple clients and they will all get the notifications\n\n## Functions\n\n```go\nfunc EnterEventWebhookHandler(si WebhookReceiverInterface, errHandler func(w http.ResponseWriter, r *http.Request, err error), middlewares ...WebhookReceiverMiddlewareFunc) http.Handler\n```\nEnterEventWebhookHandler returns an http.Handler for the EnterEvent webhook. The caller is responsible for registering this handler at the appropriate path.\n\n```go\nfunc ExitEventWebhookHandler(si WebhookReceiverInterface, errHandler func(w http.ResponseWriter, r *http.Request, err error), middlewares ...WebhookReceiverMiddlewareFunc) http.Handler\n```\nExitEventWebhookHandler returns an http.Handler for the ExitEvent webhook. The caller is responsible for registering this handler at the appropriate path.\n\n```go\nfunc GetOpenAPISpecJSON() ([]byte, error)\n```\nGetOpenAPISpecJSON returns the raw OpenAPI spec as JSON bytes.\n\n```go\nfunc Handler(si ServerInterface) http.Handler\n```\nHandler creates http.Handler with routing matching OpenAPI spec.\n\n```go\nfunc HandlerFromMux(si ServerInterface, m ServeMux) http.Handler\n```\nHandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.\n\n```go\nfunc HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler\n```\nHandlerFromMuxWithBaseURL creates http.Handler with routing and a base URL.\n\n```go\nfunc HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler\n```\nHandlerWithOptions creates http.Handler with additional options.\n\n```go\nfunc NewEnterEventWebhookRequest(targetURL string, body EnterEventJSONRequestBody) (*http.Request, error)\n```\nNewEnterEventWebhookRequest creates a POST request for the webhook with application/json body\n\n```go\nfunc NewEnterEventWebhookRequestWithBody(targetURL string, contentType string, body io.Reader) (*http.Request, error)\n```\nNewEnterEventWebhookRequestWithBody creates a POST request for the webhook with any body\n\n```go\nfunc NewExitEventWebhookRequest(targetURL string, body ExitEventJSONRequestBody) (*http.Request, error)\n```\nNewExitEventWebhookRequest creates a POST request for the webhook with application/json body\n\n```go\nfunc NewExitEventWebhookRequestWithBody(targetURL string, contentType string, body io.Reader) (*http.Request, error)\n```\nNewExitEventWebhookRequestWithBody creates a POST request for the webhook with any body\n\n## Types\n\n```go\ntype EnterEventJSONRequestBody = Person\n```\n\n```go\ntype Error struct {\n\t// Error code\n\tCode int32 `form:\"code\" json:\"code\"`\n\t// Error message\n\tMessage string `form:\"message\" json:\"message\"`\n}\n```\n\\#/components/schemas/Error\n\n```go\nfunc (s *Error) ApplyDefaults()\n```\nApplyDefaults sets default values for fields that are nil.\n\n```go\ntype ExitEventJSONRequestBody = Person\n```\n\n```go\ntype HttpRequestDoer interface {\n\tDo(req *http.Request) (*http.Response, error)\n}\n```\nHttpRequestDoer performs HTTP requests. The standard http.Client implements this interface.\n\n```go\ntype InvalidParamFormatError struct {\n\tParamName string\n\tErr       error\n}\n```\nInvalidParamFormatError is returned when a parameter has an invalid format.\n\n```go\nfunc (e *InvalidParamFormatError) Error() string\n```\n\n```go\nfunc (e *InvalidParamFormatError) Unwrap() error\n```\n\n```go\ntype MiddlewareFunc func(http.Handler) http.Handler\n```\nMiddlewareFunc is a middleware function type.\n\n```go\ntype Person struct {\n\t// Name of the person who badged in or out\n\tName string `form:\"name\" json:\"name\"`\n}\n```\n\\#/components/schemas/Person\n\n```go\nfunc (s *Person) ApplyDefaults()\n```\nApplyDefaults sets default values for fields that are nil.\n\n```go\ntype PostAPIWebhookKindParameter string\n```\n\\#/paths//api/webhook/{kind}/post/parameters/0/schema\n\n```go\nconst (\n\tEnterEvent PostAPIWebhookKindParameter = \"enterEvent\"\n\tExitEvent  PostAPIWebhookKindParameter = \"exitEvent\"\n)\n```\n\n```go\ntype RequestEditorFn func(ctx context.Context, req *http.Request) error\n```\nRequestEditorFn is the function signature for the RequestEditor callback function. It may already be defined if client code is also generated; this is a compatible redeclaration.\n\n```go\ntype RequiredHeaderError struct {\n\tParamName string\n\tErr       error\n}\n```\nRequiredHeaderError is returned when a required header is missing.\n\n```go\nfunc (e *RequiredHeaderError) Error() string\n```\n\n```go\nfunc (e *RequiredHeaderError) Unwrap() error\n```\n\n```go\ntype RequiredParamError struct {\n\tParamName string\n}\n```\nRequiredParamError is returned when a required parameter is missing.\n\n```go\nfunc (e *RequiredParamError) Error() string\n```\n\n```go\ntype ServeMux interface {\n\tHandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))\n\tServeHTTP(w http.ResponseWriter, r *http.Request)\n}\n```\nServeMux is an abstraction of http.ServeMux.\n\n```go\ntype ServerInterface interface {\n\t// Deregister a webhook\n\t// (DELETE /api/webhook/{id})\n\tDeregisterWebhook(w http.ResponseWriter, r *http.Request, id oapiCodegenTypesPkg.UUID)\n\t// Register a webhook\n\t// (POST /api/webhook/{kind})\n\tRegisterWebhook(w http.ResponseWriter, r *http.Request, kind string)\n}\n```\nServerInterface represents all server handlers.\n\n```go\ntype ServerInterfaceWrapper struct {\n\tHandler            ServerInterface\n\tHandlerMiddlewares []MiddlewareFunc\n\tErrorHandlerFunc   func(w http.ResponseWriter, r *http.Request, err error)\n}\n```\nServerInterfaceWrapper converts HTTP requests to parameters.\n\n```go\nfunc (siw *ServerInterfaceWrapper) DeregisterWebhook(w http.ResponseWriter, r *http.Request)\n```\nDeregisterWebhook operation middleware\n\n```go\nfunc (siw *ServerInterfaceWrapper) RegisterWebhook(w http.ResponseWriter, r *http.Request)\n```\nRegisterWebhook operation middleware\n\n```go\ntype SimpleWebhookInitiator struct {\n\t*WebhookInitiator\n}\n```\nSimpleWebhookInitiator wraps WebhookInitiator with typed responses for operations that have unambiguous response types. Methods return the success type directly, and HTTP errors are returned as \\*WebhookHttpError\\[E] where E is the error type.\n\n```go\nfunc NewSimpleWebhookInitiator(opts ...WebhookInitiatorOption) (*SimpleWebhookInitiator, error)\n```\nNewSimpleWebhookInitiator creates a new SimpleWebhookInitiator which wraps a WebhookInitiator.\n\n```go\ntype StdHTTPServerOptions struct {\n\tBaseURL          string\n\tBaseRouter       ServeMux\n\tMiddlewares      []MiddlewareFunc\n\tErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)\n}\n```\nStdHTTPServerOptions configures the StdHTTP server.\n\n```go\ntype TooManyValuesForParamError struct {\n\tParamName string\n\tCount     int\n}\n```\nTooManyValuesForParamError is returned when a parameter has too many values.\n\n```go\nfunc (e *TooManyValuesForParamError) Error() string\n```\n\n```go\ntype UnescapedCookieParamError struct {\n\tParamName string\n\tErr       error\n}\n```\nUnescapedCookieParamError is returned when a cookie parameter cannot be unescaped.\n\n```go\nfunc (e *UnescapedCookieParamError) Error() string\n```\n\n```go\nfunc (e *UnescapedCookieParamError) Unwrap() error\n```\n\n```go\ntype UnmarshalingParamError struct {\n\tParamName string\n\tErr       error\n}\n```\nUnmarshalingParamError is returned when a parameter cannot be unmarshaled.\n\n```go\nfunc (e *UnmarshalingParamError) Error() string\n```\n\n```go\nfunc (e *UnmarshalingParamError) Unwrap() error\n```\n\n```go\ntype WebhookHttpError[E any] struct {\n\tStatusCode int\n\tBody       E\n\tRawBody    []byte\n}\n```\nWebhookHttpError represents an HTTP error response from the webhook. The type parameter E is the type of the parsed error body.\n\n```go\nfunc (e *WebhookHttpError[E]) Error() string\n```\n\n```go\ntype WebhookInitiator struct {\n\t// Doer for performing requests, typically a *http.Client with any\n\t// customized settings, such as certificate chains.\n\tClient HttpRequestDoer\n\n\t// A list of callbacks for modifying requests which are generated before sending over\n\t// the network.\n\tRequestEditors []RequestEditorFn\n}\n```\nWebhookInitiator sends webhook requests to target URLs. Unlike Client, it has no stored base URL — the full target URL is provided per-call.\n\n```go\nfunc NewWebhookInitiator(opts ...WebhookInitiatorOption) (*WebhookInitiator, error)\n```\nNewWebhookInitiator creates a new WebhookInitiator with reasonable defaults.\n\n```go\nfunc (p *WebhookInitiator) EnterEvent(ctx context.Context, targetURL string, body EnterEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)\n```\nEnterEvent sends a POST webhook request with application/json body\n\n```go\nfunc (p *WebhookInitiator) EnterEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)\n```\nEnterEventWithBody sends a POST webhook request Person entered the building\n\n```go\nfunc (p *WebhookInitiator) ExitEvent(ctx context.Context, targetURL string, body ExitEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)\n```\nExitEvent sends a POST webhook request with application/json body\n\n```go\nfunc (p *WebhookInitiator) ExitEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)\n```\nExitEventWithBody sends a POST webhook request Person exited the building\n\n```go\ntype WebhookInitiatorInterface interface {\n\t// EnterEventWithBody sends a POST webhook request\n\tEnterEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)\n\tEnterEvent(ctx context.Context, targetURL string, body EnterEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)\n\t// ExitEventWithBody sends a POST webhook request\n\tExitEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)\n\tExitEvent(ctx context.Context, targetURL string, body ExitEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)\n}\n```\nWebhookInitiatorInterface is the interface specification for the webhook initiator.\n\n```go\ntype WebhookInitiatorOption func(*WebhookInitiator) error\n```\nWebhookInitiatorOption allows setting custom parameters during construction.\n\n```go\nfunc WithWebhookHTTPClient(doer HttpRequestDoer) WebhookInitiatorOption\n```\nWithWebhookHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.\n\n```go\nfunc WithWebhookRequestEditorFn(fn RequestEditorFn) WebhookInitiatorOption\n```\nWithWebhookRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.\n\n```go\ntype WebhookReceiverInterface interface {\n\t// Person entered the building\n\t// HandleEnterEventWebhook handles the POST webhook request.\n\tHandleEnterEventWebhook(w http.ResponseWriter, r *http.Request)\n\t// Person exited the building\n\t// HandleExitEventWebhook handles the POST webhook request.\n\tHandleExitEventWebhook(w http.ResponseWriter, r *http.Request)\n}\n```\nWebhookReceiverInterface represents handlers for receiving webhook requests.\n\n```go\ntype WebhookReceiverMiddlewareFunc func(http.Handler) http.Handler\n```\nWebhookReceiverMiddlewareFunc is a middleware function for webhook receiver handlers.\n\n```go\ntype WebhookRegistration struct {\n\t// URL to receive webhook events\n\tURL string `form:\"url\" json:\"url\"`\n}\n```\n\\#/components/schemas/WebhookRegistration\n\n```go\nfunc (s *WebhookRegistration) ApplyDefaults()\n```\nApplyDefaults sets default values for fields that are nil.\n\n```go\ntype WebhookRegistrationResponse struct {\n\t// Unique identifier for this webhook registration\n\tID oapiCodegenTypesPkg.UUID `form:\"id\" json:\"id\"`\n}\n```\n\\#/components/schemas/WebhookRegistrationResponse\n\n```go\nfunc (s *WebhookRegistrationResponse) ApplyDefaults()\n```\nApplyDefaults sets default values for fields that are nil.\n\n","path":"github.com/oapi-codegen/oapi-codegen-exp/experimental/examples/webhook","name":"doorbadge","synopsis":"Package doorbadge provides an example of OpenAPI 3.1 webhooks.","isRedistributable":true}
