Skip to content
.gitconfig syntax parser
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
configs
.gitignore
.travis.yml
LICENSE
README.md
errors.go
goconfig.go
goconfig_test.go

README.md

goconfig

Travis Build Status

Table of contents

  1. Introduction
  2. Usage
  3. Contributing
  4. Reporting bugs

1. Introduction

This project parses config files that have the same syntax as gitconfig files. It is a minimal parser, and maybe a writer sometime in the future. It has no knowledge of git-specific keys and as such, does not provide any convenience methods like config.GetUserName(). For these, look into go-gitconfig

Most of the code was copied and translated to Go from git/config.c

2. Usage

Currently, there is only one function: Parse.

import "os/user"
import "path/filepath"
import "io/ioutil"
import "github.com/muja/goconfig"

user, _ := user.Current()
// don't forget to handle error!
gitconfig := filepath.Join(user.HomeDir, ".gitconfig")
bytes, _ := ioutil.ReadFile(gitconfig)

config, lineno, err := goconfig.Parse(bytes)
if err != nil {
  // Note: config is non-nil and contains successfully parsed values
  log.Fatalf("Error on line %d: %v.\n", err)
}
fmt.Println(config["user.name"])
fmt.Println(config["user.email"])

3. Contributing

Contributions are welcome! Fork -> Push -> Pull request.

4. Bug report / suggestions

Just create an issue! I will try to reply as soon as possible.

You can’t perform that action at this time.