# readini **Repository Path**: xiezhx9/readini ## Basic Information - **Project Name**: readini - **Description**: Golang ini reader lib - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README *package readini // import "gitee.com/xiezhx9/readini"* # type ## type Section map[string]string Section 封装map[string]string ### func (s Section) getVal(key string) 获得相应key的值,假定已经确定有该key ### func (s Section) newVal(key, val string) 为Section插入新的键值对 ## type Configuration map[string]Section Configuration 封装map[string]map[string]string ### func (c Configuration) getSection(key string) (Section, error) 获得相应key的值,假定已经确定有该key ### func (c Configuration) newSection(key string) 为Configuration插入新的键值对 ## type NoSuchSectionException string NoSuchSectionException 段不存在异常 ## type NoSuchKeyException string NoSuchKeyException 键不存在异常 ## type NoSuchFileException string NoSuchFileException 没有该文件异常 ## type ReadlineException string ReadlineException 是读取文件异常 ## type Listener interface Listener 接口 ## type MyListener MyListener 是实现了Listener接口 # func ReadFileToConfig(filename string) (Configuration, error) ReadFileToConfig is to read file to Configuration struct # func Watch(filename string, lis Listener) (Configuration, error) Watch 接受文件名和Listener,等到文件被修改就返回这个配置文件 # func WatchWithOption(filename string, listener Listener, com byte) (Configuration, error) WatchWithOption 可以显式指定注释符号 # Example ```go var mylistener MyListener mylistener.channel = make(chan int) cfg, err := Watch("test.ini", mylistener) //Watch会阻塞整个进程,需要手动修改test.ini文件 fmt.Printf("%v\n", err) for key, value := range cfg { fmt.Println("Key:", key, "Value:", value) } ``` # Output ``` Key: DEFAULT Value: map[app_mode:development] Key: paths Value: map[data:/home/git/grafana] Key: server Value: map[enforce_domain:tru http_port:9999 protocol:http] ```