Documentation
¶
Overview ¶
Package config 提供了加载配置项内容的各类方法
Index ¶
- func LoadJSON(f fs.FS, path string, v interface{}) error
- func LoadXML(f fs.FS, path string, v interface{}) error
- func LoadYAML(f fs.FS, path string, v interface{}) error
- func NewServer(name, version string, f fs.FS, c catalog.Catalog, b result.BuildFunc) (*server.Server, error)
- type Cache
- type Certificate
- type Duration
- type Error
- type HTTP
- type LetsEncrypt
- type Router
- type Webconfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶ added in v0.39.0
type Cache struct {
// 表示缓存的方式
//
// 目前支持以下几种试:
// - memory 以内存作为缓存;
// - memcached 以 memcached 作为缓存;
// - redis 以 redis 作为缓存;
Type string `yaml:"type" json:"type" xml:"type,attr"`
// 表示连接缓存服务器的参数
//
// 如果类型为 memory,此值为 time.Duration 格式的参数,用于表示执行回收的间隔;
// 如果为 memcached,则为服务器列表,多个服务器,以分号作为分隔;
// 如果为 redis,则为符合 Redis URI scheme 的字符串,可参考 https://www.iana.org/assignments/uri-schemes/prov/redis
DSN string `yaml:"dsn" json:"dsn" xml:"dsn"`
}
Cache 缓存的相关配置
type Certificate ¶ added in v0.34.0
type Certificate struct {
Cert string `yaml:"cert,omitempty" json:"cert,omitempty" xml:"cert,omitempty"`
Key string `yaml:"key,omitempty" json:"key,omitempty" xml:"key,omitempty"`
}
Certificate 证书管理
type Duration ¶ added in v0.34.0
Duration 封装 time.Duration 以实现对 JSON、XML 和 YAML 的解析
func (Duration) MarshalText ¶ added in v0.39.0
MarshalText encoding.TextMarshaler 接口
func (*Duration) UnmarshalText ¶ added in v0.39.0
UnmarshalText encoding.TextUnmarshaler 接口
type Error ¶ added in v0.21.0
type Error struct {
Config, Field, Message string
Value interface{}
}
Error 表示配置内容字段错误
type HTTP ¶ added in v0.34.0
type HTTP struct {
// 网站的域名证书
//
// 不能同时与 LetsEncrypt 生效
Certificates []*Certificate `yaml:"certificates,omitempty" json:"certificates,omitempty" xml:"certificates,omitempty"`
// 配置 Let's Encrypt 证书
//
// 不能同时与 Certificates 生效
LetsEncrypt *LetsEncrypt `yaml:"letsEncrypt,omitempty" json:"letsEncrypt,omitempty" xml:"letsEncrypt,omitempty"`
// 应用于 http.Server 的几个变量
ReadTimeout Duration `yaml:"readTimeout,omitempty" json:"readTimeout,omitempty" xml:"readTimeout,attr,omitempty"`
WriteTimeout Duration `yaml:"writeTimeout,omitempty" json:"writeTimeout,omitempty" xml:"writeTimeout,attr,omitempty"`
IdleTimeout Duration `yaml:"idleTimeout,omitempty" json:"idleTimeout,omitempty" xml:"idleTimeout,attr,omitempty"`
ReadHeaderTimeout Duration `yaml:"readHeaderTimeout,omitempty" json:"readHeaderTimeout,omitempty" xml:"readHeaderTimeout,attr,omitempty"`
MaxHeaderBytes int `yaml:"maxHeaderBytes,omitempty" json:"maxHeaderBytes,omitempty" xml:"maxHeaderBytes,attr,omitempty"`
// contains filtered or unexported fields
}
HTTP 与 http 请求相关的设置
type LetsEncrypt ¶ added in v0.39.0
type LetsEncrypt struct {
Domains []string `yaml:"domains" json:"domains" xml:"domains"`
Cache string `yaml:"cache" json:"cache" xml:"cache"`
Email string `yaml:"email,omitempty" json:"email,omitempty" xml:"email,omitempty"`
ForceRSA bool `yaml:"forceRSA,omitempty" json:"forceRSA,omitempty" xml:"forceRSA,attr,omitempty"`
// 定义提早几天开始续订,如果为 0 表示提早 30 天。
RenewBefore uint `yaml:"renewBefore,omitempty" json:"renewBefore,omitempty" xml:"renewBefore,attr,omitempty"`
}
LetsEncrypt Let's Encrypt 的相关设置
type Router ¶ added in v0.34.0
type Router struct {
// 是否禁用自动生成 OPTIONS 和 HEAD 请求的处理
DisableOptions bool `yaml:"disableOptions,omitempty" json:"disableOptions,omitempty" xml:"disableOptions,attr,omitempty"`
DisableHead bool `yaml:"disableHead,omitempty" json:"disableHead,omitempty" xml:"disableHead,attr,omitempty"`
SkipCleanPath bool `yaml:"skipCleanPath,omitempty" json:"skipCleanPath,omitempty" xml:"skipCleanPath,attr,omitempty"`
}
Router 路由的相关配置
type Webconfig ¶ added in v0.39.0
type Webconfig struct {
XMLName struct{} `yaml:"-" json:"-" xml:"web"`
// 网站的根目录所在
//
// 比如 https://example.com/api/
Root string `yaml:"root,omitempty" json:"root,omitempty" xml:"root,omitempty"`
// 与路由设置相关的配置项
Router *Router `yaml:"router,omitempty" json:"router,omitempty" xml:"router,omitempty"`
// 与 HTTP 请求相关的设置项
HTTP *HTTP `yaml:"http,omitempty" json:"http,omitempty" xml:"http,omitempty"`
// 指定插件的搜索方式
//
// 通过 glob 语法搜索插件,比如:
// ~/plugins/*.so
// 具体可参考:https://golang.org/pkg/path/filepath/#Glob
// 为空表示没有插件。
//
// 当前仅支持部分系统,具体可查看:https://golang.org/pkg/plugin/
Plugins string `yaml:"plugins,omitempty" json:"plugins,omitempty" xml:"plugins,omitempty"`
// 时区名称
//
// 可以是 Asia/Shanghai 等,具体可参考:
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
//
// 为空和 Local(注意大小写) 值都会被初始化本地时间。
Timezone string `yaml:"timezone,omitempty" json:"timezone,omitempty" xml:"timezone,omitempty"`
// 指定缓存对象
//
// 如果为空,则会采用内存作为缓存对象。
Cache *Cache `yaml:"cache,omitempty" json:"cache,omitempty" xml:"cache,omitempty"`
// contains filtered or unexported fields
}
Webconfig 配置内容
Click to show internal directories.
Click to hide internal directories.