# conf [](https://oc.neonxp.ru) [](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) [](https://oc.neonxp.ru) [](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