GithubHelp home page GithubHelp logo

duzhanyuan / goconfig Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unknwon/goconfig

0.0 1.0 0.0 131 KB

Package goconfig is a fully functional and comments-support configuration file (.ini) parser.

License: Apache License 2.0

Go 100.00%

goconfig's Introduction

goconfig Build Status Go Walker

中文文档

IMPORTANT

  • This library is under bug fix only mode, which means no more features will be added.
  • I'm continuing working on better Go code with a different library: ini.

About

Package goconfig is a easy-use, comments-support configuration file parser for the Go Programming Language, which provides a structure similar to what you would find on Microsoft Windows INI files.

The configuration file consists of sections, led by a [section] header and followed by name:value or name=value entries. Note that leading whitespace is removed from values. The optional values can contain format strings which refer to other values in the same section, or values in a special DEFAULT section. Comments are indicated by ";" or "#"; comments may begin anywhere on a single line.

Features

  • It simplified operation processes, easy to use and undersatnd; therefore, there are less chances to have errors.
  • It uses exactly the same way to access a configuration file as you use Windows APIs, so you don't need to change your code style.
  • It supports read recursion sections.
  • It supports auto increment of key.
  • It supports READ and WRITE configuration file with comments each section or key which all the other parsers don't support!!!!!!!
  • It supports get value through type bool, float64, int, int64 and string, methods that start with "Must" means ignore errors and get zero-value if error occurs, or you can specify a default value.
  • It's able to load multiple files to overwrite key values.

Installation

go get github.com/Unknwon/goconfig

Or

gopm get github.com/Unknwon/goconfig

API Documentation

Go Walker.

Example

Please see conf.ini as an example.

Usage

  • Function LoadConfigFile load file(s) depends on your situation, and return a variable with type ConfigFile.
  • GetValue gives basic functionality of getting a value of given section and key.
  • Methods like Bool, Int, Int64 return corresponding type of values.
  • Methods start with Must return corresponding type of values and returns zero-value of given type if something goes wrong.
  • SetValue sets value to given section and key, and inserts somewhere if it does not exist.
  • DeleteKey deletes by given section and key.
  • Finally, SaveConfigFile saves your configuration to local file system.
  • Use method Reload in case someone else modified your file(s).
  • Methods contains Comment help you manipulate comments.
  • LoadFromReader allows loading data without an intermediate file.
  • SaveConfigData added, which writes configuration to an arbitrary writer.
  • ReloadData allows to reload data from memory.

Note that you cannot mix in-memory configuration with on-disk configuration.

More Information

  • All characters are CASE SENSITIVE, BE CAREFUL!

Credits

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

goconfig's People

Contributors

unknwon avatar admpub avatar ncw avatar slene avatar klauspost avatar orthographic-pedant avatar

Watchers

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