https://github.com/codeation/inifile
Package inifile implements parsing a simple INI file
https://github.com/codeation/inifile
go golang golang-library ini ini-file ini-parser
Last synced: 8 months ago
JSON representation
Package inifile implements parsing a simple INI file
- Host: GitHub
- URL: https://github.com/codeation/inifile
- Owner: codeation
- License: mit
- Created: 2018-08-01T18:58:00.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-15T10:29:30.000Z (almost 6 years ago)
- Last Synced: 2024-12-12T18:48:04.840Z (over 1 year ago)
- Topics: go, golang, golang-library, ini, ini-file, ini-parser
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inifile
Package inifile implements parsing a simple INI file
[](https://godoc.org/github.com/codeation/inifile)
# Installation
To install inifile package:
```
go get -u github.com/codeation/inifile
```
# Examples
sample.ini file:
```
port=8080
host=127.0.0.1
[node]
name=server.local
ip=10.0.0.11
```
sample.go file:
```
package main
import (
"fmt"
"github.com/codeation/inifile"
)
func main() {
ini, err := inifile.Read("sample.ini")
if err != nil {
fmt.Println(err)
return
}
fmt.Println("port=", ini.Get("", "port"))
fmt.Println("node.name=", ini.Get("node", "name"))
}
```
output:
```
$ go run sample.go
port= 8080
node.name= server.local
```
# Environment variable
You can specify a full path to INI file via the environment variable. For example:
```
$ SAMPLE_INI=/etc/server_configuration.ini go run sample.go
```
The environment variable is checked only if
the parameter of inifile.Read does not contain the directory name.
The name of the environment variable is the file name in uppercase,
the dot is replaced by an underscore.
# Command output encapsulation
**Please note that executing external commands can lead to application vulnerabilities.
Command output encapsulation is disabled by default.**
You can use command output as INI file variable value. For example, as string of INI file:
```
one_time_password=$(pwgen -s 16)
```
To enable command output encapsulation, call inifile.Command in golang file:
```
ini, _ := inifile.Read("sample.ini")
ini.Command(true)
fmt.Println("One time password is", ini.Get("", "one_time_password"))
```
See the [documentation](https://godoc.org/github.com/codeation/inifile) for details.