This package provides parsers for reading configuration files from other web servers (Apache/httpd, Nginx, etc.) and converting them to FastHTTP JSON format.
The parser system is designed to be modular and extensible:
- Parser Interface: Defines how parsers work
- Registry: Manages available parsers
- Converter: Transforms parsed configs to FastHTTP format
- Separate from main app: All parsing logic is isolated here
Parses Apache httpd.conf configuration files and converts them to FastHTTP format.
Supported Directives:
Listen- Port configurationUser/Group- Process user/groupServerName/ServerAlias- Virtual host namesDocumentRoot- Document root directory<VirtualHost>- Virtual host blocks<Directory>/<Location>- Location blocksProxyPass/ProxyPassMatch- Proxy configurationScriptAlias- CGI configurationDirectoryIndex- Index filesAddType- MIME typesInclude/IncludeOptional- Include files
# Convert Apache httpd.conf to FastHTTP JSON
./fasthttp convert --from apache --input /etc/httpd/conf/httpd.conf --output fasthttp.json
# Or use the API
./fasthttp convert --from apache --input /etc/httpd/conf/httpd.confimport "fasthttp/parser"
// Create registry
registry := parser.NewRegistry()
// Parse Apache config
parsed, err := registry.ParseFile("/etc/httpd/conf/httpd.conf")
if err != nil {
log.Fatal(err)
}
// Convert to FastHTTP config
converter := parser.NewFastHTTPConverter()
baseConfig := &config.Config{} // or load existing
fastHTTPConfig, err := converter.Convert(parsed, baseConfig)
if err != nil {
log.Fatal(err)
}
// Save to JSON
configJSON, _ := json.MarshalIndent(fastHTTPConfig, "", " ")
os.WriteFile("fasthttp.json", configJSON, 0644)To add support for other web servers (e.g., Nginx):
- Implement the
Parserinterface:
type MyParser struct{}
func (p *MyParser) CanParse(filePath string) bool {
// Check if this parser can handle the file
}
func (p *MyParser) Parse(filePath string) (*ParsedConfig, error) {
// Parse the file and return ParsedConfig
}- Register it in
registry.go:
registry.Register(NewMyParser())- Not all Apache directives are supported
- Some complex configurations may need manual adjustment
- PHP-FPM socket paths may need to be configured separately
- SSL/TLS configuration is not converted (configure separately)