GithubHelp home page GithubHelp logo

simpleconf's Introduction

simpleConf

install

go get -u github.com/Me1onRind/simpleConf

go version >= 1.9 because use sync.Map to make sure thread safe

introduct

​ Simply way to load the fixed-type like ini file and get value

; use ';' or '#' to comment
[test] ; section name
name  = simpleConf # string
float = 12.0       # float
str   = "12.0"     # string
int   = 12         # int
str   = "12"       # string, will overwrite last str

​ After load configure file, you can get section and get value by key in any file (thread safe)

// main.go
simpleConf.GetConf("./conf/myconf.conf")
// other.go
name := simpleConf.GetSection("test").GetStr("name")

hot load configure file if you need (thread safe)

simpleConf.HotLoad()

example

package main

import "github.com/Me1onRind/simpleConf"
import "fmt"

func init() {
	// console output debug info
	// default is false
	simpleConf.IsDebug = true

	// Only hot load the file loaded after HotLoad()
	// It's not necessary
	simpleConf.HotLoad()

	// load single file
	simpleConf.GetConf("./test.ini")

	// load files
	simpleConf.GetBatchConf(simpleConf.F{
		"./test.ini",
		"./test1.ini",
	})
}

func main() {
	/*
	 * [db@test]
	 * host=127.0.0.1
	 * port = 3306
	 */
	section := simpleConf.GetSection("db@test")
	fmt.Println(section.GetInt("port")) // 3306
	fmt.Println(section.GetStr("port")) // ""
	fmt.Println(section.GetStr("host")) // 127.0.0.1
}

API

GetConf : load single configure file
GetBatchConf: load configure files
HotLoad: use inotify system call to litsen file change
GetSection: get section (return an Section struct pointer)
GetStr/GetInt/GetFloat/GetInterface: get value under section

option

IsDebug : show debug info in console

simpleconf's People

Contributors

me1onrind avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.