conf

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 2 Imported by: 14

README

README

Export the env to the shell

export PRJ_ROOT=$HOME/ws/test

Example for RootDir

package db

import (
	"github.com/gwaylib/conf"
	"github.com//gwaylib/qsql"
	_ "github.com/go-sql-driver/mysql"
)

var dbFile = 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)
}

Example for ini read

example $HOME/ws/test/etc/etc.ini

[test]
str: abc

```golang
package db

import (
	"github.com/gwaylib/conf"
	"github.com/gwaylib/conf/ini"
)

func main() {
    path := conf.RootDir() + "/etc/"
    etc := ini.NewIni(path).Get("etc.ini")
    str := etc.String("test", "str")
    if str != "abc" {
        panic("expect abc, but : " + str)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RootDir

func RootDir() string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL