https://github.com/gwaylib/conf
conf package for go project
https://github.com/gwaylib/conf
Last synced: 5 months ago
JSON representation
conf package for go project
- Host: GitHub
- URL: https://github.com/gwaylib/conf
- Owner: gwaylib
- License: mit
- Created: 2018-04-10T07:48:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-10-30T05:58:33.000Z (8 months ago)
- Last Synced: 2026-01-18T04:46:14.836Z (5 months ago)
- Language: Go
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# README
Export the env to the shell
```shell
export PRJ_ROOT=$HOME/ws/test
```
Example for `RootDir`
```golang
package db
import (
"os/filepath"
"github.com/gwaylib/conf"
"github.com//gwaylib/qsql"
_ "github.com/go-sql-driver/mysql"
)
var dbFile = filepath.Join(conf.RootDir(), "etc/db.cfg")
func DB(section string) *qsql.DB {
return qsql.CacheDB(dbFile, section)
}
func HasDB(section string) (*qsql.DB, error) {
return qsql.HasDB(dbFile, section)
}
```
For realtime ini read
```golang
package db
import (
"github.com/gwaylib/conf"
"github.com/gwaylib/conf/ini"
)
func main() {
etcRoot := filepath.Join(conf.RootDir(), "etc")
etc := ini.NewIni(etcRoot).GetFile("etc.ini") // read disk file every times.
str := etc.String("test", "str")
if str != "abc" {
panic("expect abc, but : " + str)
}
}
```
For memory cache ini read
```
package db
import (
"github.com/gwaylib/conf"
"github.com/gwaylib/conf/ini"
)
func main() {
etcRoot := filepath.Join(conf.RootDir(), "etc")
// etcCache := ini.NewTimeoutIniCache(etcRoot, 5 * time.Munite) // the cache should reload when loaded after 5*time.Minute
etcCache := ini.NewCacheIni(etcRoot).GetFile("etc.ini")
str := etc.String("test", "str")
if str != "abc" {
panic("expect abc, but : " + str)
}
}
```