gin

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: 4 Imported by: 0

README

Gin Framework Example (Regular)

This example demonstrates how to integrate go-openapi-validator with the Gin-gonic framework using manual route registration.

Features

  • Middleware Integration: Seamlessly validates requests and responses using Gin's middleware pattern.
  • Manual Routing: Standard Gin route definitions (r.GET, r.POST, etc.).
  • Automatic Documentation: Serves Swagger UI at /docs.

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

The validator is initialized and then used as a middleware wrapper for the Gin engine:

v, _ := validator.New("openapi.yaml")
r := gin.Default()

// Register routes manually
r.GET("/health/liveness", handleLiveness)

// Wrap and serve
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