8000 GitHub - Hargeek/gin-auto-redoc: A Go package to automatically register Redoc documentation for a Gin application that already includes Swagger documentation
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A Go package to automatically register Redoc documentation for a Gin application that already includes Swagger documentation

License

Notifications You must be signed in to change notification settings

Hargeek/gin-auto-redoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | 简体中文

gin-auto-redoc

A Go package for automatically registering Redoc API documentation pages for your Gin applications with Swagger (OpenAPI) documentation

Go Version Gin Version GoDoc Contributors License

Installation

go get github.com/hargeek/gin-auto-redoc

Usage

Register the Redoc route in your Gin application

import (
    ginautodoc "github.com/hargeek/gin-auto-redoc"
    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.New()
    ginautodoc.Register(r)
    r.Run()
}

Configuration

Customize Swagger Route

By default, the Swagger Documentation is available at /api/v1/swagger and Redoc documentation is available at /api/v1/doc. To customize these paths, call SetConfig with your desired configuration before registering the middleware.

ginautodoc.SetConfig(ginautodoc.Config{
    SwaggerPath: "/custom/swagger",
})
ginautodoc.Register(r)

Reverse Proxy

If your documentation is served through a reverse proxy and the path is rewritten, you need to pass the X-Forwarded-Prefix header to the service, otherwise you will not be able to access it, for example

  • nginx configuration example:
location /custom_prefix/ {```
    proxy_pass http://localhost:8080;
    proxy_set_header X-Forwarded-Prefix "/custom_prefix";
}
  • Kubernetes ingress configuration example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
      proxy_set_header X-Forwarded-Prefix "/custom_prefix";
spec:
  ingressClassName: nginx
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          service:
            name: api-service
            port:
              number: 8080
        path: /custom_prefix/(.*)$
        pathType: Prefix

Accessing Redoc

Once you have started your Gin application, you can access the Redoc documentation at http://localhost:<port>/api/v1/doc/index.html

redoc-preview

About

A Go package to automatically register Redoc documentation for a Gin application that already includes Swagger documentation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0