ini #
Ini
Simple and practical module for manipulating ini/cfg file.
Documentation
You can access the documentation here.
Install
v install Ddiidev.ini
Or
v install https://github.com/Ddiidev/ini-v
Usage
import ldedev.ini // or "import ini" depends on how it was installed.
struct Keys {
pub:
peoples struct {
p1 string
p2 string
}
ages struct {
a1 int
a2 int
}
}
const s = r'[peoples]
p1=André
p2=Luiz
[ages]
a1=26
a2=29
'
fn main() {
k := ini.reader_to[Keys](s)!
dump(k)
}
result:
[.
Functionalities
- "read_ini" to map
- "serrialize" to string
- "write_ini" to file ini
- "deserialize" string to file ini
- "reader_to[T]" file/content for type T
It is still not possible to write a T object to the ini file.
Licença
fn deserialize #
fn deserialize(content string) map[string]map[string]string
deserialize Deserializes a string in ini format into a map.
Example
content := r'[conf]
conf1 = true
'
c := deserialize(content)
println(c['conf']['conf1'])
fn read_ini #
fn read_ini(content_or_path string) !map[string]map[string]string
reader_ini Deserialize the file of the ini format to map.
Example
c := reader_ini('./file.ini')!
println(c['conf']['conf1'])
fn reader_to #
fn reader_to[T](pathOrContent string) !T
reader_to[T] Deserialize the file or contents of the ini format to a struct.
Example
struct Keys {
pub:
conf struct {
pub:
conf1 bool
}
}
content := r'[conf]
conf1 = true
'
c := reader_to[Keys](content)!
println(c.conf.conf1)
fn serrialize #
fn serrialize(content map[string]map[string]string) string
serrialize Serialize map ini into string in ini format.
Example
c := reader_ini('./file.ini')!
s := serrialize(c)
println(s)
fn write_ini #
fn write_ini(content map[string]map[string]string, path string) !
write_ini writes the ini object to an ini format file.
Example
mut c := reader_ini('./file.ini')!
c['conf']['conf1'] = 'false'
write_ini(c, './file.ini')
// OR
write_ini({
'conf': {
'conf1': 'false'
}
}, './file.ini')!