Documentation
¶
Index ¶
- Constants
- type AggregateConfig
- type AuthConfig
- type AuthType
- type Contact
- type DocumentPathSelector
- type DocumentSource
- type DocumentSpec
- func (d *DocumentSpec) AddSource(source *DocumentSource) *DocumentSpec
- func (d *DocumentSpec) Disable() *DocumentSpec
- func (d *DocumentSpec) Enable() *DocumentSpec
- func (d *DocumentSpec) WithDescription(description string) *DocumentSpec
- func (d *DocumentSpec) WithTitle(title string) *DocumentSpec
- func (d *DocumentSpec) WithVersion(version string) *DocumentSpec
- type License
- type ServiceSpec
- func (s *ServiceSpec) AddTag(tag string) *ServiceSpec
- func (s *ServiceSpec) Disable() *ServiceSpec
- func (s *ServiceSpec) Enable() *ServiceSpec
- func (s *ServiceSpec) WithBasePath(basePath string) *ServiceSpec
- func (s *ServiceSpec) WithDescription(description string) *ServiceSpec
- func (s *ServiceSpec) WithName(name string) *ServiceSpec
- func (s *ServiceSpec) WithTags(tags []string) *ServiceSpec
- func (s *ServiceSpec) WithVersion(version string) *ServiceSpec
- type Swagger
- func (c *Swagger) AddAggregateDocument(document *DocumentSpec) *Swagger
- func (c *Swagger) AddAggregateService(service *ServiceSpec) *Swagger
- func (c *Swagger) AddSharedDefinitionPrefix(prefix string) *Swagger
- func (c *Swagger) Clone() internal.Configurable
- func (c *Swagger) Disable() *Swagger
- func (c *Swagger) DisableAggregate() *Swagger
- func (c *Swagger) DisableCDN() *Swagger
- func (c *Swagger) Enable() *Swagger
- func (c *Swagger) EnableAggregate() *Swagger
- func (c *Swagger) EnableCDN() *Swagger
- func (c *Swagger) Get() interface{}
- func (c *Swagger) GetAuthType() AuthType
- func (c *Swagger) GetCDNBundleJS() string
- func (c *Swagger) GetCDNCSSURL() string
- func (c *Swagger) GetCDNFavicon16() string
- func (c *Swagger) GetCDNFavicon32() string
- func (c *Swagger) GetCDNPresetJS() string
- func (c *Swagger) GetFullJSONPath() string
- func (c *Swagger) GetFullUIPath() string
- func (c *Swagger) GetSharedDefinitionPrefixes() []string
- func (c *Swagger) IsAggregateEnabled() bool
- func (c *Swagger) IsAuthEnabled() bool
- func (c *Swagger) IsEnabled() bool
- func (c *Swagger) Reset() *Swagger
- func (c *Swagger) Set(data interface{})
- func (c *Swagger) Validate() error
- func (c *Swagger) ValidateAuth() error
- func (c *Swagger) WithAggregate(aggregate *AggregateConfig) *Swagger
- func (c *Swagger) WithAggregateDocuments(documents []*DocumentSpec) *Swagger
- func (c *Swagger) WithAggregateMode(mode string) *Swagger
- func (c *Swagger) WithAggregateServices(services []*ServiceSpec) *Swagger
- func (c *Swagger) WithAggregateUILayout(layout string) *Swagger
- func (c *Swagger) WithAuth(auth *AuthConfig) *Swagger
- func (c *Swagger) WithBasePath(basePath string) *Swagger
- func (c *Swagger) WithBasicAuth(username, password string) *Swagger
- func (c *Swagger) WithBearerAuth(token string) *Swagger
- func (c *Swagger) WithCDNBaseURL(baseURL string) *Swagger
- func (c *Swagger) WithCDNFallbackURL(fallbackURL string) *Swagger
- func (c *Swagger) WithCDNVersion(version string) *Swagger
- func (c *Swagger) WithContact(contact *Contact) *Swagger
- func (c *Swagger) WithCustomCDNURLs(cssURL, bundleJS, presetJS, favicon32, favicon16 string) *Swagger
- func (c *Swagger) WithCustomPaths(jsonPath, uiPath string) *Swagger
- func (c *Swagger) WithDefaults() *Swagger
- func (c *Swagger) WithDescription(description string) *Swagger
- func (c *Swagger) WithDocumentInfo(title, description string) *Swagger
- func (c *Swagger) WithEnabled(enabled bool) *Swagger
- func (c *Swagger) WithJSONPath(path string) *Swagger
- func (c *Swagger) WithLicense(license *License) *Swagger
- func (c *Swagger) WithModuleName(moduleName string) *Swagger
- func (c *Swagger) WithSharedDefinitionPrefixes(prefixes []string) *Swagger
- func (c *Swagger) WithSpecPath(path string) *Swagger
- func (c *Swagger) WithTitle(title string) *Swagger
- func (c *Swagger) WithUIPath(path string) *Swagger
- func (c *Swagger) WithVersion(version string) *Swagger
- func (c *Swagger) WithYamlPath(path string) *Swagger
Constants ¶
const ( // CDN 资源文件路径 CDNPathCSS = "/swagger-ui.css" CDNPathBundleJS = "/swagger-ui-bundle.js" CDNPathPresetJS = "/swagger-ui-standalone-preset.js" CDNPathFavicon32 = "/favicon-32x32.png" CDNPathFavicon16 = "/favicon-16x16.png" // CDN 基础 URL 模板 CDNBaseURLUnpkg = "https://unpkg.com/swagger-ui-dist@" CDNBaseURLJsDelivr = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@" )
CDN 资源路径常量
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateConfig ¶
type AggregateConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用聚合
Mode string `mapstructure:"mode" yaml:"mode" json:"mode"` // 聚合模式: merge|selector
Services []*ServiceSpec `mapstructure:"services" yaml:"services" json:"services"` // 微服务列表
Documents []*DocumentSpec `mapstructure:"documents" yaml:"documents" json:"documents"` // 独立文档列表
UILayout string `mapstructure:"ui-layout" yaml:"ui-layout" json:"uiLayout"` // UI布局: tabs|dropdown|list
}
AggregateConfig 聚合Swagger配置
type AuthConfig ¶
type AuthConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用认证
Type AuthType `mapstructure:"type" yaml:"type" json:"type"` // 认证类型
Username string `mapstructure:"username" yaml:"username" json:"username"` // 用户名(基本认证)
Password string `mapstructure:"password" yaml:"password" json:"password"` // 密码(基本认证)
Token string `mapstructure:"token" yaml:"token" json:"token"` // Token(Bearer认证)
HeaderName string `mapstructure:"header-name" yaml:"header-name" json:"headerName"` // 自定义header名称
HeaderValue string `mapstructure:"header-value" yaml:"header-value" json:"headerValue"` // 自定义header值
}
AuthConfig Swagger认证配置
type Contact ¶
type Contact struct {
Name string `mapstructure:"name" yaml:"name" json:"name"` // 联系人姓名
URL string `mapstructure:"url" yaml:"url" json:"url"` // 联系URL
Email string `mapstructure:"email" yaml:"email" json:"email"` // 联系邮箱
}
Contact Swagger联系信息
type DocumentPathSelector ¶
type DocumentPathSelector struct {
Path string `mapstructure:"path" yaml:"path" json:"path"` // Swagger路径,如 /v1/open-platform/apps
Methods []string `mapstructure:"methods" yaml:"methods" json:"methods"` // 可选的HTTP方法列表,留空表示该路径下全部方法
}
DocumentPathSelector 独立文档中的接口选择器
type DocumentSource ¶
type DocumentSource struct {
Service string `mapstructure:"service" yaml:"service" json:"service"` // 来源服务名,对应 aggregate.services[].name
Paths []*DocumentPathSelector `mapstructure:"paths" yaml:"paths" json:"paths"` // include 的兼容简写,留空表示该服务全部路径
Include []*DocumentPathSelector `mapstructure:"include" yaml:"include" json:"include"` // 显式包含的路径列表,留空表示该服务全部路径
Exclude []*DocumentPathSelector `mapstructure:"exclude" yaml:"exclude" json:"exclude"` // 需要排除的路径列表
}
DocumentSource 独立文档的数据源
func NewDocumentSource ¶
func NewDocumentSource(service string) *DocumentSource
NewDocumentSource 创建新的独立文档来源配置
func (*DocumentSource) AddExcludePath ¶
func (d *DocumentSource) AddExcludePath(path string, methods ...string) *DocumentSource
AddExcludePath 添加排除路径选择器
func (*DocumentSource) AddIncludePath ¶
func (d *DocumentSource) AddIncludePath(path string, methods ...string) *DocumentSource
AddIncludePath 添加包含路径选择器
func (*DocumentSource) GetEffectiveInclude ¶
func (d *DocumentSource) GetEffectiveInclude() []*DocumentPathSelector
GetEffectiveInclude 获取生效的 include 选择器,优先使用 include,其次兼容 paths
type DocumentSpec ¶
type DocumentSpec struct {
Name string `mapstructure:"name" yaml:"name" json:"name"` // 文档名称,同时用于路由标识
Title string `mapstructure:"title" yaml:"title" json:"title"` // 文档标题
Description string `mapstructure:"description" yaml:"description" json:"description"` // 文档描述
Version string `mapstructure:"version" yaml:"version" json:"version"` // 文档版本
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用
Sources []*DocumentSource `mapstructure:"sources" yaml:"sources" json:"sources"` // 文档来源
}
DocumentSpec 独立Swagger文档配置
func NewDocumentSpec ¶
func NewDocumentSpec(name string) *DocumentSpec
NewDocumentSpec 创建新的独立Swagger文档配置
func (*DocumentSpec) AddSource ¶
func (d *DocumentSpec) AddSource(source *DocumentSource) *DocumentSpec
AddSource 添加文档来源
func (*DocumentSpec) WithDescription ¶
func (d *DocumentSpec) WithDescription(description string) *DocumentSpec
WithDescription 设置文档描述
func (*DocumentSpec) WithTitle ¶
func (d *DocumentSpec) WithTitle(title string) *DocumentSpec
WithTitle 设置文档标题
func (*DocumentSpec) WithVersion ¶
func (d *DocumentSpec) WithVersion(version string) *DocumentSpec
WithVersion 设置文档版本
type License ¶
type License struct {
Name string `mapstructure:"name" yaml:"name" json:"name"` // 许可证名称
URL string `mapstructure:"url" yaml:"url" json:"url"` // 许可证URL
}
License Swagger许可证信息
type ServiceSpec ¶
type ServiceSpec struct {
Name string `mapstructure:"name" yaml:"name" json:"name"` // 服务名称
Description string `mapstructure:"description" yaml:"description" json:"description"` // 服务描述
SpecPath string `mapstructure:"spec-path" yaml:"spec-path" json:"specPath"` // Swagger规范文件路径
URL string `mapstructure:"url" yaml:"url" json:"url"` // 远程Swagger文档URL
Version string `mapstructure:"version" yaml:"version" json:"version"` // 服务版本
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用
BasePath string `mapstructure:"base-path" yaml:"base-path" json:"basePath"` // API基础路径前缀
Tags []string `mapstructure:"tags" yaml:"tags" json:"tags"` // 服务标签
}
ServiceSpec 单个微服务Swagger规范配置
func NewRemoteServiceSpec ¶
func NewRemoteServiceSpec(name, description, url string) *ServiceSpec
NewRemoteServiceSpec 创建远程服务规范配置
func NewServiceSpec ¶
func NewServiceSpec(name, description, specPath string) *ServiceSpec
NewServiceSpec 创建新的服务规范配置
func (*ServiceSpec) WithBasePath ¶
func (s *ServiceSpec) WithBasePath(basePath string) *ServiceSpec
WithBasePath 设置API基础路径
func (*ServiceSpec) WithDescription ¶
func (s *ServiceSpec) WithDescription(description string) *ServiceSpec
WithDescription 设置服务描述
func (*ServiceSpec) WithName ¶
func (s *ServiceSpec) WithName(name string) *ServiceSpec
WithName 设置服务名称
func (*ServiceSpec) WithTags ¶
func (s *ServiceSpec) WithTags(tags []string) *ServiceSpec
WithTags 设置服务标签
func (*ServiceSpec) WithVersion ¶
func (s *ServiceSpec) WithVersion(version string) *ServiceSpec
WithVersion 设置服务版本
type Swagger ¶
type Swagger struct {
ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名称
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用Swagger
JSONPath string `mapstructure:"json-path" yaml:"json-path" json:"jsonPath"` // Swagger JSON文件路径
UIPath string `mapstructure:"ui-path" yaml:"ui-path" json:"uiPath"` // Swagger UI路由路径
YamlPath string `mapstructure:"yaml-path" yaml:"yaml-path" json:"yamlPath"` // Swagger YAML文件路径
SpecPath string `mapstructure:"spec-path" yaml:"spec-path" json:"specPath"` // Swagger规范文件路径(自动检测格式)
Title string `mapstructure:"title" yaml:"title" json:"title"` // 文档标题
Description string `mapstructure:"description" yaml:"description" json:"description"` // 文档描述
Version string `mapstructure:"version" yaml:"version" json:"version"` // Swagger版本
Contact *Contact `mapstructure:"contact" yaml:"contact" json:"contact"` // 联系信息
License *License `mapstructure:"license" yaml:"license" json:"license"` // 许可证信息
Auth *AuthConfig `mapstructure:"auth" yaml:"auth" json:"auth"` // 认证配置
Aggregate *AggregateConfig `mapstructure:"aggregate" yaml:"aggregate" json:"aggregate"` // 聚合配置
HotReload bool `mapstructure:"hot-reload" yaml:"hot-reload" json:"hotReload"` // 是否启用文件热重载
// CDN 资源配置
CDNVersion string `mapstructure:"cdn-version" yaml:"cdn-version" json:"cdnVersion"` // Swagger UI CDN版本
CDNBaseURL string `mapstructure:"cdn-base-url" yaml:"cdn-base-url" json:"cdnBaseURL"` // CDN基础URL
CDNCSSURL string `mapstructure:"cdn-css-url" yaml:"cdn-css-url" json:"cdnCSSURL"` // CSS文件URL
CDNBundleJS string `mapstructure:"cdn-bundle-js" yaml:"cdn-bundle-js" json:"cdnBundleJS"` // Bundle JS URL
CDNPresetJS string `mapstructure:"cdn-preset-js" yaml:"cdn-preset-js" json:"cdnPresetJS"` // Preset JS URL
CDNFavicon32 string `mapstructure:"cdn-favicon32" yaml:"cdn-favicon32" json:"cdnFavicon32"` // 32x32 Favicon URL
CDNFavicon16 string `mapstructure:"cdn-favicon16" yaml:"cdn-favicon16" json:"cdnFavicon16"` // 16x16 Favicon URL
UseCDN bool `mapstructure:"use-cdn" yaml:"use-cdn" json:"useCDN"` // 是否使用CDN资源
CDNFallbackURL string `mapstructure:"cdn-fallback-url" yaml:"cdn-fallback-url" json:"cdnFallbackURL"` // CDN备用URL
}
Swagger Swagger配置结构
func (*Swagger) AddAggregateDocument ¶
func (c *Swagger) AddAggregateDocument(document *DocumentSpec) *Swagger
AddAggregateDocument 添加单个独立文档
func (*Swagger) AddAggregateService ¶
func (c *Swagger) AddAggregateService(service *ServiceSpec) *Swagger
AddAggregateService 添加单个聚合服务
func (*Swagger) AddSharedDefinitionPrefix ¶
AddSharedDefinitionPrefix 添加单个共享定义前缀
func (*Swagger) DisableAggregate ¶
DisableAggregate 禁用聚合功能
func (*Swagger) EnableAggregate ¶
EnableAggregate 启用聚合功能
func (*Swagger) GetCDNBundleJS ¶
GetCDNBundleJS 获取Bundle JS URL(支持备用)
func (*Swagger) GetCDNFavicon16 ¶
GetCDNFavicon16 获取16x16 Favicon URL(支持备用)
func (*Swagger) GetCDNFavicon32 ¶
GetCDNFavicon32 获取32x32 Favicon URL(支持备用)
func (*Swagger) GetCDNPresetJS ¶
GetCDNPresetJS 获取Preset JS URL(支持备用)
func (*Swagger) GetFullJSONPath ¶
GetFullJSONPath 获取完整的JSON路径
func (*Swagger) GetSharedDefinitionPrefixes ¶
GetSharedDefinitionPrefixes 获取共享定义前缀列表
func (*Swagger) IsAggregateEnabled ¶
IsAggregateEnabled 检查聚合功能是否启用
func (*Swagger) WithAggregate ¶
func (c *Swagger) WithAggregate(aggregate *AggregateConfig) *Swagger
WithAggregate 设置聚合配置
func (*Swagger) WithAggregateDocuments ¶
func (c *Swagger) WithAggregateDocuments(documents []*DocumentSpec) *Swagger
WithAggregateDocuments 设置独立文档列表
func (*Swagger) WithAggregateMode ¶
WithAggregateMode 设置聚合模式
func (*Swagger) WithAggregateServices ¶
func (c *Swagger) WithAggregateServices(services []*ServiceSpec) *Swagger
WithAggregateServices 设置聚合服务列表
func (*Swagger) WithAggregateUILayout ¶
WithAggregateUILayout 设置UI布局
func (*Swagger) WithBasePath ¶
WithBasePath 设置基础路径(同时设置JSON和UI路径)
func (*Swagger) WithBasicAuth ¶
WithBasicAuth 设置基本认证
func (*Swagger) WithBearerAuth ¶
WithBearerAuth 设置Bearer Token认证
func (*Swagger) WithCDNBaseURL ¶
WithCDNBaseURL 设置CDN基础URL
func (*Swagger) WithCDNFallbackURL ¶
WithCDNFallbackURL 设置CDN备用URL
func (*Swagger) WithCDNVersion ¶
WithCDNVersion 设置CDN版本
func (*Swagger) WithContact ¶
WithContact 设置联系信息
func (*Swagger) WithCustomCDNURLs ¶
func (c *Swagger) WithCustomCDNURLs(cssURL, bundleJS, presetJS, favicon32, favicon16 string) *Swagger
WithCustomCDNURLs 自定义CDN资源URLs
func (*Swagger) WithCustomPaths ¶
WithCustomPaths 自定义JSON和UI路径
func (*Swagger) WithDefaults ¶
WithDefaults 使用默认配置填充未设置的字段
func (*Swagger) WithDescription ¶
WithDescription 设置文档描述
func (*Swagger) WithDocumentInfo ¶
WithDocumentInfo 设置文档信息(标题和描述)
func (*Swagger) WithEnabled ¶
WithEnabled 设置是否启用Swagger
func (*Swagger) WithJSONPath ¶
WithJSONPath 设置Swagger JSON文件路径
func (*Swagger) WithLicense ¶
WithLicense 设置许可证信息
func (*Swagger) WithModuleName ¶
WithModuleName 设置模块名称
func (*Swagger) WithSharedDefinitionPrefixes ¶
WithSharedDefinitionPrefixes 设置共享定义前缀列表
func (*Swagger) WithSpecPath ¶
WithSpecPath 设置Swagger规范文件路径
func (*Swagger) WithUIPath ¶
WithUIPath 设置Swagger UI路由路径
func (*Swagger) WithVersion ¶
WithVersion 设置Swagger版本
func (*Swagger) WithYamlPath ¶
WithYamlPath 设置Swagger YAML文件路径