# conf [![🌱 Organic Code -- Code written by human](https://oc.neonxp.ru/organiccode.svg)](https://oc.neonxp.ru) [![Go Doc](https://pkg.go.dev/badge/go.neonxp.ru/conf.svg)](https://pkg.go.dev/go.neonxp.ru/conf) Go Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° для парсинга ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΎΠ½Π½Ρ‹Ρ… Ρ„Π°ΠΉΠ»ΠΎΠ² `.conf` ΠΏΠΎΡ…ΠΎΠΆΠ΅ΠΌ Π½Π° классичСскиС UNIX ΠΊΠΎΠ½Ρ„ΠΈΠ³ΠΈ, ΠΊΠ°ΠΊ Ρƒ nginx ΠΈΠ»ΠΈ bind9. [English version](#english) ## Установка ```bash go get go.neonxp.ru/conf ``` ## ΠžΡΠΎΠ±Π΅Π½Π½ΠΎΡΡ‚ΠΈ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π° - **Π”ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹**: `directive arg1 arg2;` - **Π”ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ с Ρ‚Π΅Π»ΠΎΠΌ**: `directive arg1 arg2 { ... }` - **Π’ΠΈΠΏΡ‹ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ΠΎΠ²**: строки (Π΄Π²ΠΎΠΉΠ½Ρ‹Π΅/ΠΎΠ΄ΠΈΠ½Π°Ρ€Π½Ρ‹Π΅ ΠΊΠ°Π²Ρ‹Ρ‡ΠΊΠΈ/backticks для многострочных строк), числа (Ρ†Π΅Π»Ρ‹Π΅/Π΄Ρ€ΠΎΠ±Π½Ρ‹Π΅), Π±ΡƒΠ»Π΅Π²Ρ‹ значСния - **Π’Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Π΅ Π±Π»ΠΎΠΊΠΈ**: ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½Π°Ρ Π³Π»ΡƒΠ±ΠΈΠ½Π° влоТСнности - **ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ**: `#` Π΄ΠΎ ΠΊΠΎΠ½Ρ†Π° строки - **UTF-8**: Π²ΠΊΠ»ΡŽΡ‡Π°Ρ ΠΊΠΈΡ€ΠΈΠ»Π»ΠΈΡ†Ρƒ ## Быстрый старт ```go package main import ( "fmt" "go.neonxp.ru/conf" ) func main() { // Π—Π°Π³Ρ€ΡƒΠ·ΠΊΠ° ΠΈΠ· Ρ„Π°ΠΉΠ»Π° cfg, err := conf.LoadFile("config.conf") if err != nil { panic(err) } // ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ ΠΈ Π΅Ρ‘ значСния if hostCmd := cfg.Get("server"); hostCmd != nil { fmt.Printf("Server: %v\n", hostCmd.Value()) } // Навигация ΠΏΠΎ Π²Π»ΠΎΠΆΠ΅Π½Π½ΠΎΠΉ структурС sslEnabled := cfg.Get("server").Group().Get("ssl").Group().Get("enabled") fmt.Printf("SSL enabled: %v\n", sslEnabled.Value()) } ``` ## ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΎΠ½Π½ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π° ```conf # ΠŸΡ€ΠΎΡΡ‚Ρ‹Π΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ Π±Π΅Π· Ρ‚Π΅Π»Π° listen 8080; host "127.0.0.1"; debug false; # Π”ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ с Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ ΠΈ Ρ‚Π΅Π»ΠΎΠΌ server "web" { host "localhost"; port 8080; ssl { enabled true; cert "/etc/ssl/cert.pem"; key "/etc/ssl/key.pem"; } middleware "auth" { enabled true; secret "secret123"; } } # НСсколько Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ² с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ cache "redis" { host "redis.local"; port 6379; } cache "memcached" { host "memcached.local"; port 11211; } # ΠœΠ½ΠΎΠ³ΠΎΡΡ‚Ρ€ΠΎΡ‡Π½Ρ‹Π΅ строки template ` Hello `; ``` ## ВрСбования - Go 1.23+ (для использования `iter.Seq`) ## ЛицСнзия Π­Ρ‚ΠΎΡ‚ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ Π»ΠΈΡ†Π΅Π½Π·ΠΈΡ€ΠΎΠ²Π°Π½ Π² соотвСтствии с GNU General Public License вСрсии 3 (GPLv3). ΠŸΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎΡΡ‚ΠΈ смотритС Π² Ρ„Π°ΠΉΠ»Π΅ [LICENSE](LICENSE). ``` GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2026 Alexander NeonXP Kiryukhin Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. ``` ## Автор - АлСксандр ΠšΠΈΡ€ΡŽΡ…ΠΈΠ½ --- # conf (English) [![🌱 Organic Code -- Code written by human](https://oc.neonxp.ru/organiccode.svg)](https://oc.neonxp.ru) [![Go Doc](https://pkg.go.dev/badge/go.neonxp.ru/conf.svg)](https://pkg.go.dev/go.neonxp.ru/conf) Go library for parsing `.conf` configuration files (like many classic UNIX programms like nginx or bind9). ## Installation ```bash go get go.neonxp.ru/conf ``` ## Format Features - **Directives**: `directive arg1 arg2;` - **Directives with body**: `directive arg1 arg2 { ... }` - **Argument types**: strings (double/single quotes, backticks for multiline strings), numbers (integer/float), boolean values - **Nested blocks**: arbitrary nesting depth - **Comments**: `#` until end of line - **UTF-8**: including Cyrillic ## Quick Start ```go package main import ( "fmt" "go.neonxp.ru/conf" ) func main() { // Load from file cfg, err := conf.LoadFile("config.conf") if err != nil { panic(err) } // Get directive and its value if hostCmd := cfg.Get("server"); hostCmd != nil { fmt.Printf("Server: %v\n", hostCmd.Value()) } // Navigate through nested structure sslEnabled := cfg.Get("server").Group.Get("ssl").Group.Get("enabled") fmt.Printf("SSL enabled: %v\n", sslEnabled.Value()) } ``` ## Example Configuration File ```conf # Simple directives without body listen 8080; host "127.0.0.1"; debug false; # Directives with arguments and body server "web" { host "localhost"; port 8080; ssl { enabled true; cert "/etc/ssl/cert.pem"; key "/etc/ssl/key.pem"; } middleware "auth" { enabled true; secret "secret123"; } } # Multiple directives with same name cache "redis" { host "redis.local"; port 6379; } cache "memcached" { host "memcached.local"; port 11211; } # Multiline strings template ` Hello `; ``` ## Requirements - Go 1.23+ (for `iter.Seq`) ## License This project is licensed under GNU General Public License version 3 (GPLv3). See [LICENSE](LICENSE) file for details. ``` GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2026 Alexander NeonXP Kiryukhin Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. ``` ## Author - Alexander Kiryukhin