Code Monkey home page Code Monkey logo

goconf's Introduction

Terry-Mao/goconf

Terry-Mao/goconf is an configuration file parse module.

Requeriments

  • Go 1.2 or higher

Installation

Just pull Terry-Mao/goconf from github using go get:

# download the code
$ go get -u github.com/Terry-Mao/goconf

Usage

package main                                                                   
                                                                               
import (                                                                       
    "fmt"                                                                      
    "github.com/Terry-Mao/goconf"                                              
)                                                                              

type TestConfig struct {
	ID     int           `goconf:"core:id"`
	Col    string        `goconf:"core:col"`
	Ignore int           `goconf:"-"`
	Arr    []string      `goconf:"core:arr:,"`
	Test   time.Duration `goconf:"core:t_1:time"`
	Buf    int           `goconf:"core:buf:memory"`
}
                                                                               
func main() {                                                                  
    conf := goconf.New()                                                       
    if err := conf.Parse("./examples/conf_test.txt"); err != nil {             
        panic(err)                                                             
    }                                                                          
    core := conf.Get("core")                                                   
    if core == nil {                                                           
        panic("no core section")                                               
    }                                                                          
    id, err := core.Int("id")                                                  
    if err != nil {                                                            
        panic(err)                                                             
    }                                                                          
    fmt.Println(id)                                                            
    tf := &TestConfig{}
    if err := conf.Unmarshall(tf); err != nil {
        panic(err)
    }
    fmt.Println(tf.ID)
} 

Examples

# configuration examples
# this is comment, goconf will ignore it.

# this is the section name
[core]

# a key-value config which key is test and value is 1
test = 1

# one mb
test1 = 1mb

# one second
test2 = 1s

# boolean
test3 = true

Documentation

Read the Terry-Mao/goconf documentation from a terminal

$ godoc github.com/Terry-Mao/goconf -http=:6060

Alternatively, you can goconf online.

goconf's People

Contributors

terry-mao avatar

Watchers

James Cloos avatar  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.