gorilla

command
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 5 Imported by: 0

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

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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