apache

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: BSD-3-Clause Imports: 12 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 SitesPath = "/opt/ace/sites"

SitesPath 网站目录

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Type       string       `json:"type"` // Directory, Location, Files 等
	Args       []string     `json:"args"` // 块的参数
	Directives []*Directive `json:"directives"`
	Comments   []*Comment   `json:"comments"` // 块内注释
	Line       int          `json:"line"`
	Column     int          `json:"column"`
}

Block 配置块,如 <Directory>, <Location> 等

func (*Block) ExportWithOptions

func (b *Block) ExportWithOptions(options *ExportOptions, indent int) string

ExportWithOptions 导出块指令

type Comment

type Comment struct {
	Text   string `json:"text"`
	Line   int    `json:"line"`
	Column int    `json:"column"`
}

Comment 注释

func (*Comment) ExportWithOptions

func (c *Comment) ExportWithOptions(options *ExportOptions, indent int) string

ExportWithOptions 导出注释

type Config

type Config struct {
	Directives   []*Directive   `json:"directives"`
	VirtualHosts []*VirtualHost `json:"virtual_hosts"`
	Comments     []*Comment     `json:"comments"`
	Includes     []*Include     `json:"includes"`
}

Config Apache 配置文件的 AST 根节点

func ParseFile

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

ParseFile 从文件解析 Apache 配置

func ParseFileWithOptions

func ParseFileWithOptions(filename string, options *ParseOptions) (*Config, error)

ParseFileWithOptions 从文件解析 Apache 配置(带选项)

func ParseString

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

ParseString 从字符串解析 Apache 配置

func ParseStringWithOptions

func ParseStringWithOptions(content string, options *ParseOptions) (*Config, error)

ParseStringWithOptions 从字符串解析 Apache 配置(带选项)

func (*Config) AddVirtualHost

func (c *Config) AddVirtualHost(args ...string) *VirtualHost

AddVirtualHost 添加新虚拟主机到配置

func (*Config) Export

func (c *Config) Export() string

Export 导出整个配置为Apache配置文件格式

func (*Config) ExportWithOptions

func (c *Config) ExportWithOptions(options *ExportOptions) string

ExportWithOptions 使用指定选项导出配置

func (*Config) GetDirective

func (c *Config) GetDirective(name string) *Directive

GetDirective 根据名称查找指令

func (*Config) GetDirectives

func (c *Config) GetDirectives(name string) []*Directive

GetDirectives 根据名称查找所有匹配的指令

func (*Config) GetVirtualHost

func (c *Config) GetVirtualHost(args ...string) *VirtualHost

GetVirtualHost 根据参数查找虚拟主机

type Directive

type Directive struct {
	Name   string   `json:"name"`
	Args   []string `json:"args"`
	Line   int      `json:"line"`
	Column int      `json:"column"`
	Block  *Block   `json:"block,omitempty"` // 对于有块的指令如 <Directory>
}

Directive Apache 指令

func (*Directive) ExportWithOptions

func (d *Directive) ExportWithOptions(options *ExportOptions, indent int) string

ExportWithOptions 导出指令

type ExportOptions

type ExportOptions struct {
	// IndentStyle 缩进样式:使用空格还是制表符
	IndentStyle string // "spaces" 或 "tabs"

	// IndentSize 缩进大小(仅当IndentStyle为"spaces"时有效)
	IndentSize int

	// SortDirectives 是否对指令进行排序
	SortDirectives bool

	// IncludeComments 是否包含注释
	IncludeComments bool

	// PreserveEmptyLines 是否保留空行
	PreserveEmptyLines bool

	// FormatStyle 格式化风格
	FormatStyle string // "compact", "standard", "verbose"
}

ExportOptions 定义导出选项

func DefaultExportOptions

func DefaultExportOptions() *ExportOptions

DefaultExportOptions 返回默认的导出选项

type Include

type Include struct {
	Path   string `json:"path"`
	Line   int    `json:"line"`
	Column int    `json:"column"`
}

Include 包含其他配置文件的指令

type Lexer

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

Lexer 词法分析器

func NewLexer

func NewLexer(input io.Reader) (*Lexer, error)

NewLexer 创建一个新的词法分析器

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken 获取下一个 token

func (*Lexer) PeekToken

func (l *Lexer) PeekToken() Token

PeekToken 预览下一个 token 而不移动位置

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, typ string) 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, typ string) 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, typ string, 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) 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 {
	// ProcessIncludes 是否处理Include指令,递归加载包含的文件
	ProcessIncludes bool

	// BaseDir 基础目录,用于解析相对路径的Include文件
	BaseDir string

	// MaxIncludeDepth 最大包含深度,防止无限递归
	MaxIncludeDepth int
}

ParseOptions 定义解析器选项

func DefaultParseOptions

func DefaultParseOptions() *ParseOptions

DefaultParseOptions 返回默认的解析选项

type Parser

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

Parser Apache 配置文件解析器

func NewParser

func NewParser(input io.Reader) (*Parser, error)

NewParser 创建一个新的 Apache 配置解析器(使用默认选项)

func NewParserWithOptions

func NewParserWithOptions(input io.Reader, options *ParseOptions) (*Parser, error)

NewParserWithOptions 创建一个带选项的 Apache 配置解析器

func (*Parser) Parse

func (p *Parser) Parse() (*Config, error)

Parse 解析 Apache 配置文件并返回 AST

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, typ string) 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, typ string) 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, typ string, 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) 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 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, typ string) 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, typ string) 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, typ string, 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) 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

type Token

type Token struct {
	Type   TokenType
	Value  string
	Line   int
	Column int
}

Token 表示一个词法单元

type TokenType

type TokenType int

TokenType 表示 token 的类型

const (
	ILLEGAL TokenType = iota
	EOF
	NEWLINE
	COMMENT
	DIRECTIVE
	STRING
	LBRACE    // <
	RBRACE    // >
	SLASH     // /
	COLON     // :
	SEMICOLON // ;
	EQUAL     // =
	QUOTE     // "
	VIRTUALHOST
	BLOCKDIRECTIVE // Directory, Location 等块指令
)

type VirtualHost

type VirtualHost struct {
	Name       string       `json:"name"`
	Args       []string     `json:"args"` // 通常是 IP:Port
	Line       int          `json:"line"`
	Column     int          `json:"column"`
	Directives []*Directive `json:"directives"`
	Comments   []*Comment   `json:"comments"` // 虚拟主机内的注释
}

VirtualHost 虚拟主机配置

func (*VirtualHost) AddBlock

func (v *VirtualHost) AddBlock(blockType string, args ...string) *Directive

AddBlock 添加块指令(如 Directory, Location 等)

func (*VirtualHost) AddDirective

func (v *VirtualHost) AddDirective(name string, args ...string) *Directive

AddDirective 为虚拟主机添加指令

func (*VirtualHost) ExportWithOptions

func (v *VirtualHost) ExportWithOptions(options *ExportOptions, indent int) string

ExportWithOptions 导出虚拟主机

func (*VirtualHost) GetBlock

func (v *VirtualHost) GetBlock(blockType string, args ...string) *Block

GetBlock 获取块指令

func (*VirtualHost) GetDirective

func (v *VirtualHost) GetDirective(name string) *Directive

GetDirective 在虚拟主机中根据名称查找指令

func (*VirtualHost) GetDirectiveValue

func (v *VirtualHost) GetDirectiveValue(name string) string

GetDirectiveValue 获取指令的第一个参数值

func (*VirtualHost) GetDirectiveValues

func (v *VirtualHost) GetDirectiveValues(name string) []string

GetDirectiveValues 获取指令的所有参数值

func (*VirtualHost) GetDirectives

func (v *VirtualHost) GetDirectives(name string) []*Directive

GetDirectives 在虚拟主机中根据名称查找所有匹配的指令

func (*VirtualHost) HasDirective

func (v *VirtualHost) HasDirective(name string) bool

HasDirective 检查是否存在指定指令

func (*VirtualHost) RemoveDirective

func (v *VirtualHost) RemoveDirective(name string) bool

RemoveDirective 删除指令

func (*VirtualHost) RemoveDirectives

func (v *VirtualHost) RemoveDirectives(name string) int

RemoveDirectives 删除所有匹配名称的指令

func (*VirtualHost) SetDirective

func (v *VirtualHost) SetDirective(name string, args ...string) *Directive

SetDirective 设置指令(如果存在则更新,不存在则添加)

Jump to

Keyboard shortcuts

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