Sign inDemoInstall

Package Overview
File Explorer

Install Socket

Protect your apps from supply chain attacks


Package conf is a configuration parser that loads configuration in a struct from files and automatically creates cli flags. Just define a struct with needed configuration. Values are then taken from multiple source in this order of precedence: Default is to use lower cased field names in struct to create command line arguments. Tags can be used to specify different names, command line help message and section in conf file. Format is: conf.Path variable can be set to the path of a configuration file. For default it is initialized to the value of environment variable: Files ending with: will be parsed as INI informal standard: First letter of every key found is upper cased and than, a struct field with same name is searched: If such field name is not found than comparison is made against key specified as first element in tag. conf tries to be modular and easily extensible to support different formats. This is a work in progress, APIs can change.


Version published



|image0|_ |image1|_ |image2|_

.. |image0| image::
.. _image0:

.. |image1| image::
.. _image1:

.. |image2| image::
.. _image2:

.. contents::

A go package for configuration parsing. Automagically populates a configuration ``struct`` using configuration files & command line arguments.

It aims to be modular and easily extendible to support other formats. Only INI format supported for now.

Usage and examples
An example of utilization::

        type myConf struct {
                Address string
                Port    string
                // A command line flag "-users", which expects an int value,
                // will be created.
                // Same key name will be searched in configuration file.
                NumberOfUsers int `conf:"users,number of users,"`
                Daemon        bool
                Message       string

        func Example() {
                // To create a dafault value for a flag
                // assign it when instantiate the conf struct.
                c := myConf{Message: "A default value"}
                conf.Path = "test_data/one.ini"
                err := conf.Parse(&c)
                if err != nil {
                        log.Fatal("Unable to parse configuration", err)
                fmt.Println("address:", c.Address)
                fmt.Println("port:", c.Port)
                fmt.Println("number of users:", c.NumberOfUsers)

See the flag arguments that are automagically created::

        go run main.go -h

See `godocs <>`_ for examples and documentation.

Pull requests that add new tests, features or fixes are welcome, encouraged, and credited.


Last updated on 05 Feb 2018

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc