config

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package config 提供了从配置文件初始化 server.Options 的方法

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOptions added in v0.41.0

func NewOptions(locale *serialization.Locale, f fs.FS, logsFilename, webFilename string) (*server.Options, error)

NewOptions 从配置文件初始化 server.Options 实例

locale 指定了用于加载本地化的方法,同时其关联的 serialization.Files 也用于加载配置文件; logsFilename 和 webFilename 用于指定日志和项目的配置文件,根据扩展由 serialization.Files 负责在 f 查找文件加载;

Types

type Cache added in v0.39.0

type Cache struct {
	// 表示缓存的方式
	//
	// 目前支持以下几种试:
	// - memory 以内存作为缓存;
	// - memcached 以 memcached 作为缓存;
	// - redis 以 redis 作为缓存;
	// - file 以文件作为缓存;
	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
	// - file,表示以半有分号分隔的参数列表,可以指定以下两个参数:
	//  - path 文件路径;
	//  - gc 执行回收的间隔,time.Duration 格式;
	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

type Duration time.Duration

Duration 封装 time.Duration 以实现对 JSON、XML 和 YAML 的解析

func (Duration) Duration added in v0.34.0

func (d Duration) Duration() time.Duration

Duration 转换成 time.Duration

func (Duration) MarshalText added in v0.39.0

func (d Duration) MarshalText() ([]byte, error)

MarshalText encoding.TextMarshaler 接口

func (*Duration) UnmarshalText added in v0.39.0

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText encoding.TextUnmarshaler 接口

type Error added in v0.21.0

type Error struct {
	Config  string      // 配置文件的路径
	Field   string      // 字段名
	Message string      // 错误信息
	Value   interface{} // 原始值
}

Error 表示配置内容字段错误

func (*Error) Error added in v0.21.0

func (err *Error) Error() string

func (*Error) LocaleString added in v0.43.0

func (err *Error) LocaleString(p *message.Printer) string

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"`

	// 定义提早几天开始续订,如果为 0 表示提早 30 天。
	RenewBefore uint `yaml:"renewBefore,omitempty" json:"renewBefore,omitempty" xml:"renewBefore,attr,omitempty"`
}

LetsEncrypt Let's Encrypt 的相关设置

type Webconfig added in v0.39.0

type Webconfig struct {
	XMLName struct{} `yaml:"-" json:"-" xml:"web"`

	// 网站端口
	//
	// 格式与 net/http.Server.Addr 相同
	Port string `yaml:"port,omitempty" json:"port,omitempty" xml:"port,attr,omitempty"`

	// 是否禁用自动生成 HEAD 请求
	DisableHead bool `yaml:"disableHead,omitempty" json:"disableHead,omitempty" xml:"disableHead,attr,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"`

	// 此处列出的类型将不会被压缩
	//
	// 可以带 *,比如 text/* 表示所有 mime-type 为 text/ 开始的类型。
	IgnoreCompressTypes []string `yaml:"ignoreCompressTypes,omitempty" json:"ignoreCompressTypes,omitempty" xml:"ignoreCompressTypes,omitempty"`
	// contains filtered or unexported fields
}

Webconfig 配置内容

func (*Webconfig) NewOptions added in v0.41.0

func (conf *Webconfig) NewOptions(locale *serialization.Locale, fs fs.FS, l *logs.Logs) (*server.Options, error)

NewOptions 返回 server.Options 对象

Jump to

Keyboard shortcuts

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