docs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docs 提供 OpenAPI/Swagger 在线文档能力: 把 OpenAPI 规范文件(YAML/JSON)挂到 HTTP 服务上,并托管 Swagger UI。

使用示例(在 RegisterRoutes 中调用):

if err := docs.Register(engine, docs.Options{SpecPath: "docs/openapi.yaml"}); err != nil {
    return err
}

启用后可访问:

  • /docs Swagger UI 页面
  • /docs/openapi OpenAPI 规范文件

规范文件可手写,也可由注解工具生成(如 swag CLI:swag init 产出 swagger.json, 将 SpecPath 指向该文件即可)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(engine *gin.Engine, opts Options) error

Register 在 engine 上注册 Swagger UI 与 OpenAPI 规范路由.

  • GET <prefix> Swagger UI 页面
  • GET <prefix>/openapi OpenAPI 规范文件(按文件扩展名返回对应 Content-Type)

SpecPath 文件不存在时返回错误,保证启动即失败(fail fast), 避免线上部署后才发现文档缺失。

Types

type Options

type Options struct {
	// SpecPath OpenAPI 规范文件路径(.yaml/.yml/.json),必填
	SpecPath string
	// RoutePrefix 文档路由前缀,默认 "/docs"
	RoutePrefix string
}

Options 文档注册选项.

Jump to

Keyboard shortcuts

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