apache

package
v3.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedirectStartNum = 100 // 重定向配置起始序号 (100-199)
	RedirectEndNum   = 199
	ProxyStartNum    = 200 // 代理配置起始序号 (200-299)
	ProxyEndNum      = 299
)

配置文件序号范围

View Source
const DefaultVhostConf = `` /* 489-byte string literal not displayed */

DefaultVhostConf 默认配置模板

View Source
const DisablePage = "/opt/ace/server/apache/htdocs/stop.html"

DisablePage 禁用页面路径

View Source
const HSTSValue = "max-age=31536000"

HSTSValue 是 HSTS 响应头的默认 max-age(1 年)

View Source
const SitesPath = "/opt/ace/sites"

SitesPath 网站目录

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument added in v3.2.5

type Argument struct {
	Value string     // 解引号后的真实值,如 www.example.com
	Quote QuoteStyle // 复现时据此加回引号
}

Argument 是一个指令或块参数:解引号后的纯值 + 原始引号风格

func (Argument) String added in v3.2.5

func (a Argument) String() string

String 返回参数的纯值,便于直接当字符串使用

type Block

type Block struct {
	Name string
	Args []Argument
	// contains filtered or unexported fields
}

Block 是容器块,如 <Directory /x> ... </Directory>,可任意深度嵌套 VirtualHost 即 Name=="VirtualHost" 的 Block,不再是独立类型

func Blk added in v3.2.5

func Blk(name string, args ...string) *Block

Blk 构造一个块,参数自动判断引号;用 Add 填充子节点

func (*Block) Add added in v3.2.5

func (l *Block) Add(name string, args ...string) *Directive

Add 追加一条指令,参数自动判断引号,返回新指令

func (*Block) AddBlock added in v3.2.5

func (l *Block) AddBlock(name string, args ...string) *Block

AddBlock 追加一个块,返回新块

func (*Block) AddVirtualHost added in v3.2.5

func (l *Block) AddVirtualHost(args ...string) *Block

AddVirtualHost 追加一个 VirtualHost 块

func (*Block) Append added in v3.2.5

func (b *Block) Append(nodes ...Node) *Block

Append 向块追加子节点,返回自身以便链式调用

func (*Block) AppendArg added in v3.2.5

func (b *Block) AppendArg(value string)

AppendArg 追加一个块参数

func (*Block) ArgValues added in v3.2.5

func (b *Block) ArgValues() []string

ArgValues 返回块参数的纯值切片

func (*Block) Find added in v3.2.5

func (l *Block) Find(path string) []*Directive

Find 按点路径查找指令,跨越嵌套块,如 Find("IfModule.Proxy.BalancerMember")

func (*Block) FindBlocks added in v3.2.5

func (l *Block) FindBlocks(path string) []*Block

FindBlocks 按点路径查找块,如 FindBlocks("IfModule.Proxy")

func (*Block) FindOne added in v3.2.5

func (l *Block) FindOne(path string) *Directive

FindOne 返回点路径命中的首个指令,无命中返回 nil

func (*Block) Get added in v3.2.5

func (l *Block) Get(name string) *Directive

Get 返回首个匹配名称的指令

func (*Block) GetAll added in v3.2.5

func (l *Block) GetAll(name string) []*Directive

GetAll 返回所有匹配名称的指令

func (*Block) GetBlock added in v3.2.5

func (l *Block) GetBlock(name string, args ...string) *Block

GetBlock 返回首个匹配类型(及可选参数)的块

func (*Block) Has added in v3.2.5

func (l *Block) Has(name string) bool

Has 判断是否存在指定指令

func (*Block) Remove added in v3.2.5

func (l *Block) Remove(name string) bool

Remove 删除首个匹配名称的指令,返回是否删除

func (*Block) RemoveAll added in v3.2.5

func (l *Block) RemoveAll(name string) int

RemoveAll 删除所有匹配名称的指令,返回删除数量

func (*Block) RemoveFunc added in v3.2.5

func (l *Block) RemoveFunc(name string, pred func(*Directive) bool) int

RemoveFunc 删除满足谓词的匹配名称指令,返回删除数量

func (*Block) Set added in v3.2.5

func (l *Block) Set(name string, args ...string) *Directive

Set 设置指令:存在则更新参数,否则追加

func (*Block) SetArgs added in v3.2.5

func (b *Block) SetArgs(args ...string)

SetArgs 替换块参数,自动判断引号

func (*Block) Value added in v3.2.5

func (l *Block) Value(name string) string

Value 返回指令首个参数值,不存在返回空串

func (*Block) Values added in v3.2.5

func (l *Block) Values(name string) []string

Values 返回指令全部参数值

func (*Block) VirtualHosts added in v3.2.5

func (l *Block) VirtualHosts() []*Block

VirtualHosts 返回所有 VirtualHost 块

type Comment

type Comment struct {
	Text string
}

Comment 是整行注释,Text 为 # 之后的原文(含前导空格)

func Cmt added in v3.2.5

func Cmt(text string) *Comment

Cmt 构造一条注释,传入不含 # 的纯文本

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config 是一个配置单元(apache.conf 或片段文件)的根节点

func ParseFile

func ParseFile(filename string) (*Config, error)

ParseFile 从文件解析配置(容错模式)

func ParseFragment added in v3.2.5

func ParseFragment(content string) (*Config, error)

ParseFragment 解析片段文件内容(裸指令/块列表,容错模式)

func ParseString

func ParseString(content string) (*Config, error)

ParseString 从字符串解析配置(容错模式)

func (*Config) Add added in v3.2.5

func (l *Config) Add(name string, args ...string) *Directive

Add 追加一条指令,参数自动判断引号,返回新指令

func (*Config) AddBlock added in v3.2.5

func (l *Config) AddBlock(name string, args ...string) *Block

AddBlock 追加一个块,返回新块

func (*Config) AddVirtualHost

func (l *Config) AddVirtualHost(args ...string) *Block

AddVirtualHost 追加一个 VirtualHost 块

func (*Config) Append added in v3.2.5

func (l *Config) Append(nodes ...Node)

Append 向容器追加节点

func (*Config) Export

func (c *Config) Export() string

Export 保序导出(用于片段):按节点原有顺序输出,规范缩进

func (*Config) Find added in v3.2.5

func (l *Config) Find(path string) []*Directive

Find 按点路径查找指令,跨越嵌套块,如 Find("IfModule.Proxy.BalancerMember")

func (*Config) FindBlocks added in v3.2.5

func (l *Config) FindBlocks(path string) []*Block

FindBlocks 按点路径查找块,如 FindBlocks("IfModule.Proxy")

func (*Config) FindOne added in v3.2.5

func (l *Config) FindOne(path string) *Directive

FindOne 返回点路径命中的首个指令,无命中返回 nil

func (*Config) Get added in v3.2.5

func (l *Config) Get(name string) *Directive

Get 返回首个匹配名称的指令

func (*Config) GetAll added in v3.2.5

func (l *Config) GetAll(name string) []*Directive

GetAll 返回所有匹配名称的指令

func (*Config) GetBlock added in v3.2.5

func (l *Config) GetBlock(name string, args ...string) *Block

GetBlock 返回首个匹配类型(及可选参数)的块

func (*Config) Has added in v3.2.5

func (l *Config) Has(name string) bool

Has 判断是否存在指定指令

func (*Config) Remove added in v3.2.5

func (l *Config) Remove(name string) bool

Remove 删除首个匹配名称的指令,返回是否删除

func (*Config) RemoveAll added in v3.2.5

func (l *Config) RemoveAll(name string) int

RemoveAll 删除所有匹配名称的指令,返回删除数量

func (*Config) RemoveFunc added in v3.2.5

func (l *Config) RemoveFunc(name string, pred func(*Directive) bool) int

RemoveFunc 删除满足谓词的匹配名称指令,返回删除数量

func (*Config) Render added in v3.2.5

func (c *Config) Render() string

Render 规范化导出(用于主文件 Save):按 order 表稳定排序后输出

func (*Config) Set added in v3.2.5

func (l *Config) Set(name string, args ...string) *Directive

Set 设置指令:存在则更新参数,否则追加

func (*Config) Value added in v3.2.5

func (l *Config) Value(name string) string

Value 返回指令首个参数值,不存在返回空串

func (*Config) Values added in v3.2.5

func (l *Config) Values(name string) []string

Values 返回指令全部参数值

func (*Config) VirtualHosts

func (l *Config) VirtualHosts() []*Block

VirtualHosts 返回所有 VirtualHost 块

type Directive

type Directive struct {
	Name string
	Args []Argument
}

Directive 是普通指令,独占一行,如 ServerName a b

func Dir added in v3.2.5

func Dir(name string, args ...string) *Directive

Dir 构造一条指令,参数自动判断引号

type Node added in v3.2.5

type Node interface {
	// contains filtered or unexported methods
}

Node 是配置中可出现在容器内的元素:指令、块或注释

type PHPVhost

type PHPVhost struct {
	// contains filtered or unexported fields
}

PHPVhost PHP 虚拟主机

func NewPHPVhost

func NewPHPVhost(configDir string) (*PHPVhost, error)

NewPHPVhost 创建 PHP 虚拟主机实例

func (PHPVhost) AccessLog

func (v PHPVhost) AccessLog() string

func (PHPVhost) BasicAuth

func (v PHPVhost) BasicAuth() map[string]string

func (PHPVhost) ClearBasicAuth

func (v PHPVhost) ClearBasicAuth() error

func (PHPVhost) ClearRateLimit

func (v PHPVhost) ClearRateLimit() error

func (PHPVhost) ClearRealIP

func (v PHPVhost) ClearRealIP() error

func (PHPVhost) ClearSSL

func (v PHPVhost) ClearSSL() error

func (PHPVhost) Config

func (v PHPVhost) Config(name string, scope types.ConfigScope) string

func (PHPVhost) Enable

func (v PHPVhost) Enable() bool

func (PHPVhost) ErrorLog

func (v PHPVhost) ErrorLog() string

func (PHPVhost) Includes

func (v PHPVhost) Includes() []types.IncludeFile

func (PHPVhost) Index

func (v PHPVhost) Index() []string

func (PHPVhost) Listen

func (v PHPVhost) Listen() []types.Listen

func (*PHPVhost) PHP

func (v *PHPVhost) PHP() uint

func (PHPVhost) RateLimit

func (v PHPVhost) RateLimit() *types.RateLimit

func (PHPVhost) RealIP

func (v PHPVhost) RealIP() *types.RealIP

func (PHPVhost) Redirects

func (v PHPVhost) Redirects() []types.Redirect

func (PHPVhost) RemoveConfig

func (v PHPVhost) RemoveConfig(name string, scope types.ConfigScope) error

func (PHPVhost) Reset

func (v PHPVhost) Reset() error

func (PHPVhost) Root

func (v PHPVhost) Root() string

func (PHPVhost) SSL

func (v PHPVhost) SSL() bool

func (PHPVhost) SSLConfig

func (v PHPVhost) SSLConfig() *types.SSLConfig

func (PHPVhost) Save

func (v PHPVhost) Save() error

func (PHPVhost) ServerName

func (v PHPVhost) ServerName() []string

func (PHPVhost) SetAccessLog

func (v PHPVhost) SetAccessLog(accessLog string) error

func (PHPVhost) SetBasicAuth

func (v PHPVhost) SetBasicAuth(auth map[string]string) error

func (PHPVhost) SetConfig

func (v PHPVhost) SetConfig(name string, scope types.ConfigScope, content string) error

func (PHPVhost) SetEnable

func (v PHPVhost) SetEnable(enable bool) error

func (PHPVhost) SetErrorLog

func (v PHPVhost) SetErrorLog(errorLog string) error

func (PHPVhost) SetIncludes

func (v PHPVhost) SetIncludes(includes []types.IncludeFile) error

func (PHPVhost) SetIndex

func (v PHPVhost) SetIndex(index []string) error

func (PHPVhost) SetListen

func (v PHPVhost) SetListen(listens []types.Listen) error

func (*PHPVhost) SetPHP

func (v *PHPVhost) SetPHP(version uint) error

func (PHPVhost) SetRateLimit

func (v PHPVhost) SetRateLimit(limit *types.RateLimit) error

func (PHPVhost) SetRawConfig added in v3.2.5

func (v PHPVhost) SetRawConfig(name string, scope types.ConfigScope, content string) error

func (PHPVhost) SetRealIP

func (v PHPVhost) SetRealIP(realIP *types.RealIP) error

func (PHPVhost) SetRedirects

func (v PHPVhost) SetRedirects(redirects []types.Redirect) error

func (PHPVhost) SetRoot

func (v PHPVhost) SetRoot(root string) error

func (PHPVhost) SetSSLConfig

func (v PHPVhost) SetSSLConfig(cfg *types.SSLConfig) error

func (PHPVhost) SetServerName

func (v PHPVhost) SetServerName(serverName []string) error

type ParseOptions

type ParseOptions struct {
	// Tolerant 容错模式:遇到结构错误(孤立闭合标签、未闭合块)记录后尽力继续,不致命
	Tolerant bool
}

ParseOptions 控制解析行为

type ProxyVhost

type ProxyVhost struct {
	// contains filtered or unexported fields
}

ProxyVhost 反向代理虚拟主机

func NewProxyVhost

func NewProxyVhost(configDir string) (*ProxyVhost, error)

NewProxyVhost 创建反向代理虚拟主机实例

func (ProxyVhost) AccessLog

func (v ProxyVhost) AccessLog() string

func (ProxyVhost) BasicAuth

func (v ProxyVhost) BasicAuth() map[string]string

func (ProxyVhost) ClearBasicAuth

func (v ProxyVhost) ClearBasicAuth() error

func (*ProxyVhost) ClearProxies

func (v *ProxyVhost) ClearProxies() error

func (ProxyVhost) ClearRateLimit

func (v ProxyVhost) ClearRateLimit() error

func (ProxyVhost) ClearRealIP

func (v ProxyVhost) ClearRealIP() error

func (ProxyVhost) ClearSSL

func (v ProxyVhost) ClearSSL() error

func (*ProxyVhost) ClearUpstreams

func (v *ProxyVhost) ClearUpstreams() error

func (ProxyVhost) Config

func (v ProxyVhost) Config(name string, scope types.ConfigScope) string

func (ProxyVhost) Enable

func (v ProxyVhost) Enable() bool

func (ProxyVhost) ErrorLog

func (v ProxyVhost) ErrorLog() string

func (ProxyVhost) Includes

func (v ProxyVhost) Includes() []types.IncludeFile

func (ProxyVhost) Index

func (v ProxyVhost) Index() []string

func (ProxyVhost) Listen

func (v ProxyVhost) Listen() []types.Listen

func (*ProxyVhost) Proxies

func (v *ProxyVhost) Proxies() []types.Proxy

func (ProxyVhost) RateLimit

func (v ProxyVhost) RateLimit() *types.RateLimit

func (ProxyVhost) RealIP

func (v ProxyVhost) RealIP() *types.RealIP

func (ProxyVhost) Redirects

func (v ProxyVhost) Redirects() []types.Redirect

func (ProxyVhost) RemoveConfig

func (v ProxyVhost) RemoveConfig(name string, scope types.ConfigScope) error

func (ProxyVhost) Reset

func (v ProxyVhost) Reset() error

func (ProxyVhost) Root

func (v ProxyVhost) Root() string

func (ProxyVhost) SSL

func (v ProxyVhost) SSL() bool

func (ProxyVhost) SSLConfig

func (v ProxyVhost) SSLConfig() *types.SSLConfig

func (ProxyVhost) Save

func (v ProxyVhost) Save() error

func (ProxyVhost) ServerName

func (v ProxyVhost) ServerName() []string

func (ProxyVhost) SetAccessLog

func (v ProxyVhost) SetAccessLog(accessLog string) error

func (ProxyVhost) SetBasicAuth

func (v ProxyVhost) SetBasicAuth(auth map[string]string) error

func (ProxyVhost) SetConfig

func (v ProxyVhost) SetConfig(name string, scope types.ConfigScope, content string) error

func (ProxyVhost) SetEnable

func (v ProxyVhost) SetEnable(enable bool) error

func (ProxyVhost) SetErrorLog

func (v ProxyVhost) SetErrorLog(errorLog string) error

func (ProxyVhost) SetIncludes

func (v ProxyVhost) SetIncludes(includes []types.IncludeFile) error

func (ProxyVhost) SetIndex

func (v ProxyVhost) SetIndex(index []string) error

func (ProxyVhost) SetListen

func (v ProxyVhost) SetListen(listens []types.Listen) error

func (*ProxyVhost) SetProxies

func (v *ProxyVhost) SetProxies(proxies []types.Proxy) error

func (ProxyVhost) SetRateLimit

func (v ProxyVhost) SetRateLimit(limit *types.RateLimit) error

func (ProxyVhost) SetRawConfig added in v3.2.5

func (v ProxyVhost) SetRawConfig(name string, scope types.ConfigScope, content string) error

func (ProxyVhost) SetRealIP

func (v ProxyVhost) SetRealIP(realIP *types.RealIP) error

func (ProxyVhost) SetRedirects

func (v ProxyVhost) SetRedirects(redirects []types.Redirect) error

func (ProxyVhost) SetRoot

func (v ProxyVhost) SetRoot(root string) error

func (ProxyVhost) SetSSLConfig

func (v ProxyVhost) SetSSLConfig(cfg *types.SSLConfig) error

func (ProxyVhost) SetServerName

func (v ProxyVhost) SetServerName(serverName []string) error

func (*ProxyVhost) SetUpstreams

func (v *ProxyVhost) SetUpstreams(upstreams []types.Upstream) error

func (*ProxyVhost) Upstreams

func (v *ProxyVhost) Upstreams() []types.Upstream

type QuoteStyle added in v3.2.5

type QuoteStyle uint8

QuoteStyle 表示参数原始的引号风格,用于忠实复现

const (
	QuoteNone   QuoteStyle = iota // 无引号
	QuoteDouble                   // 双引号
	QuoteSingle                   // 单引号
)

type StaticVhost

type StaticVhost struct {
	// contains filtered or unexported fields
}

StaticVhost 纯静态虚拟主机

func NewStaticVhost

func NewStaticVhost(configDir string) (*StaticVhost, error)

NewStaticVhost 创建纯静态虚拟主机实例

func (StaticVhost) AccessLog

func (v StaticVhost) AccessLog() string

func (StaticVhost) BasicAuth

func (v StaticVhost) BasicAuth() map[string]string

func (StaticVhost) ClearBasicAuth

func (v StaticVhost) ClearBasicAuth() error

func (StaticVhost) ClearRateLimit

func (v StaticVhost) ClearRateLimit() error

func (StaticVhost) ClearRealIP

func (v StaticVhost) ClearRealIP() error

func (StaticVhost) ClearSSL

func (v StaticVhost) ClearSSL() error

func (StaticVhost) Config

func (v StaticVhost) Config(name string, scope types.ConfigScope) string

func (StaticVhost) Enable

func (v StaticVhost) Enable() bool

func (StaticVhost) ErrorLog

func (v StaticVhost) ErrorLog() string

func (StaticVhost) Includes

func (v StaticVhost) Includes() []types.IncludeFile

func (StaticVhost) Index

func (v StaticVhost) Index() []string

func (StaticVhost) Listen

func (v StaticVhost) Listen() []types.Listen

func (StaticVhost) RateLimit

func (v StaticVhost) RateLimit() *types.RateLimit

func (StaticVhost) RealIP

func (v StaticVhost) RealIP() *types.RealIP

func (StaticVhost) Redirects

func (v StaticVhost) Redirects() []types.Redirect

func (StaticVhost) RemoveConfig

func (v StaticVhost) RemoveConfig(name string, scope types.ConfigScope) error

func (StaticVhost) Reset

func (v StaticVhost) Reset() error

func (StaticVhost) Root

func (v StaticVhost) Root() string

func (StaticVhost) SSL

func (v StaticVhost) SSL() bool

func (StaticVhost) SSLConfig

func (v StaticVhost) SSLConfig() *types.SSLConfig

func (StaticVhost) Save

func (v StaticVhost) Save() error

func (StaticVhost) ServerName

func (v StaticVhost) ServerName() []string

func (StaticVhost) SetAccessLog

func (v StaticVhost) SetAccessLog(accessLog string) error

func (StaticVhost) SetBasicAuth

func (v StaticVhost) SetBasicAuth(auth map[string]string) error

func (StaticVhost) SetConfig

func (v StaticVhost) SetConfig(name string, scope types.ConfigScope, content string) error

func (StaticVhost) SetEnable

func (v StaticVhost) SetEnable(enable bool) error

func (StaticVhost) SetErrorLog

func (v StaticVhost) SetErrorLog(errorLog string) error

func (StaticVhost) SetIncludes

func (v StaticVhost) SetIncludes(includes []types.IncludeFile) error

func (StaticVhost) SetIndex

func (v StaticVhost) SetIndex(index []string) error

func (StaticVhost) SetListen

func (v StaticVhost) SetListen(listens []types.Listen) error

func (StaticVhost) SetRateLimit

func (v StaticVhost) SetRateLimit(limit *types.RateLimit) error

func (StaticVhost) SetRawConfig added in v3.2.5

func (v StaticVhost) SetRawConfig(name string, scope types.ConfigScope, content string) error

func (StaticVhost) SetRealIP

func (v StaticVhost) SetRealIP(realIP *types.RealIP) error

func (StaticVhost) SetRedirects

func (v StaticVhost) SetRedirects(redirects []types.Redirect) error

func (StaticVhost) SetRoot

func (v StaticVhost) SetRoot(root string) error

func (StaticVhost) SetSSLConfig

func (v StaticVhost) SetSSLConfig(cfg *types.SSLConfig) error

func (StaticVhost) SetServerName

func (v StaticVhost) SetServerName(serverName []string) error

Jump to

Keyboard shortcuts

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