GithubHelp home page GithubHelp logo

codeation / inifile Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 14 KB

Package inifile implements parsing a simple INI file

License: MIT License

Go 100.00%
go golang ini-parser ini-file golang-library ini

inifile's Introduction

inifile

Package inifile implements parsing a simple INI file

GoDoc

Installation

To install inifile package:

go get -u github.com/codeation/inifile

Examples

sample.ini file:

port=8080
host=127.0.0.1

[node]
name=server.local
ip=10.0.0.11

sample.go file:

package main

import (
	"fmt"

	"github.com/codeation/inifile"
)

func main() {
	ini, err := inifile.Read("sample.ini")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("port=", ini.Get("", "port"))
	fmt.Println("node.name=", ini.Get("node", "name"))
}

output:

$ go run sample.go 
port= 8080
node.name= server.local

Environment variable

You can specify a full path to INI file via the environment variable. For example:

$ SAMPLE_INI=/etc/server_configuration.ini go run sample.go

The environment variable is checked only if the parameter of inifile.Read does not contain the directory name. The name of the environment variable is the file name in uppercase, the dot is replaced by an underscore.

Command output encapsulation

Please note that executing external commands can lead to application vulnerabilities. Command output encapsulation is disabled by default.

You can use command output as INI file variable value. For example, as string of INI file:

one_time_password=$(pwgen -s 16)

To enable command output encapsulation, call inifile.Command in golang file:

    ini, _ := inifile.Read("sample.ini")
    ini.Command(true)
    fmt.Println("One time password is", ini.Get("", "one_time_password"))

See the documentation for details.

inifile's People

Contributors

codeation 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.