command
Version:
v1.0.1
Opens a new window with list of versions in this module.
Published: Dec 31, 2025
License: MIT
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Gorilla Mux Example
This example demonstrates how to integrate go-openapi-validator with the popular Gorilla Mux router.
Features
- Native Router Support: Leverages
kin-openapi's built-in Gorilla Mux router for path matching.
- Standard Middleware: Uses the standard
http.Handler middleware pattern.
- Spec Validation: Full request and response validation against
openapi.yaml.
Usage
1. Run the Server
go run main.go
2. Test Endpoints
- Liveness Check:
curl http://localhost:8081/health/liveness
- Readiness Check:
curl http://localhost:8081/health/readiness
- Swagger UI: Visit
http://localhost:8081/docs in your browser.
Code Overview
Initialization is straightforward as Gorilla Mux is the default router used by the validator:
v, _ := validator.New("openapi.yaml")
r := mux.NewRouter()
// Define routes
r.HandleFunc("/health/liveness", handleLiveness).Methods("GET")
// Apply middleware
handler := v.Middleware(r)
http.ListenAndServe(":8081", handler)
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.