lock vendor
This commit is contained in:
parent
a0e882e801
commit
79ac87c5d1
651 changed files with 221739 additions and 0 deletions
8
vendor/github.com/glacjay/goini/.gitignore
generated
vendored
Normal file
8
vendor/github.com/glacjay/goini/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.*.swp
|
||||
|
||||
*.[689]
|
||||
[689].out
|
||||
|
||||
_obj
|
||||
_test
|
||||
_testmain.go
|
||||
21
vendor/github.com/glacjay/goini/LICENSE.txt
generated
vendored
Normal file
21
vendor/github.com/glacjay/goini/LICENSE.txt
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) [year] [fullname]
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
7
vendor/github.com/glacjay/goini/Makefile
generated
vendored
Normal file
7
vendor/github.com/glacjay/goini/Makefile
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
test:
|
||||
go test
|
||||
|
||||
format:
|
||||
gofmt -w *.go
|
||||
|
||||
.PHONY: format test
|
||||
5
vendor/github.com/glacjay/goini/README.md
generated
vendored
Normal file
5
vendor/github.com/glacjay/goini/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# goini
|
||||
INI file parser in go.
|
||||
|
||||
# See Also
|
||||
For real apps, you can use [TOML](https://github.com/BurntSushi/toml) instead, which is a better INI format :-)
|
||||
0
vendor/github.com/glacjay/goini/empty.ini
generated
vendored
Normal file
0
vendor/github.com/glacjay/goini/empty.ini
generated
vendored
Normal file
18
vendor/github.com/glacjay/goini/example.ini
generated
vendored
Normal file
18
vendor/github.com/glacjay/goini/example.ini
generated
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# This is an example of ini file
|
||||
#
|
||||
|
||||
[Pizza]
|
||||
|
||||
Ham = yes;
|
||||
Mushrooms = TRUE;
|
||||
Capres = 0;
|
||||
Cheese = Non;
|
||||
|
||||
|
||||
[Wine]
|
||||
|
||||
Grape = Cabernet Sauvignon;
|
||||
Year = 1989;
|
||||
Country = Spain;
|
||||
Alcohol = 12.5;
|
||||
267
vendor/github.com/glacjay/goini/ini.go
generated
vendored
Normal file
267
vendor/github.com/glacjay/goini/ini.go
generated
vendored
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
package ini
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type Dict map[string]map[string]string
|
||||
|
||||
type Error string
|
||||
|
||||
var (
|
||||
regDoubleQuote = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*\"([^\"]*)\"$")
|
||||
regSingleQuote = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*'([^']*)'$")
|
||||
regNoQuote = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*([^#;]+)")
|
||||
regNoValue = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*([#;].*)?")
|
||||
)
|
||||
|
||||
func MustLoadReader(reader *bufio.Reader) Dict {
|
||||
dict, err := LoadReader(reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return dict
|
||||
}
|
||||
|
||||
func MustLoad(filename string) Dict {
|
||||
dict, err := Load(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return dict
|
||||
}
|
||||
|
||||
func LoadReader(reader *bufio.Reader) (dict Dict, err error) {
|
||||
dict = make(map[string]map[string]string)
|
||||
lineno := 0
|
||||
section := ""
|
||||
dict[section] = make(map[string]string)
|
||||
|
||||
for err == nil {
|
||||
l, _, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
lineno++
|
||||
|
||||
line := strings.TrimFunc(string(l), unicode.IsSpace)
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for line[len(line)-1] == '\\' {
|
||||
line = line[:len(line)-1]
|
||||
l, _, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
line += strings.TrimFunc(string(l), unicode.IsSpace)
|
||||
}
|
||||
|
||||
section, err = dict.parseLine(section, line)
|
||||
if err != nil {
|
||||
return nil, newError(
|
||||
err.Error() + fmt.Sprintf("':%d'.", lineno))
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func Load(filename string) (Dict, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
reader := bufio.NewReader(file)
|
||||
return LoadReader(reader)
|
||||
}
|
||||
|
||||
func Write(filename string, dict *Dict) error {
|
||||
buffer := dict.format()
|
||||
return ioutil.WriteFile(filename, buffer.Bytes(), 0644)
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
func (dict Dict) parseLine(section, line string) (string, error) {
|
||||
// commets
|
||||
if line[0] == '#' || line[0] == ';' {
|
||||
return section, nil
|
||||
}
|
||||
|
||||
// section name
|
||||
if line[0] == '[' && line[len(line)-1] == ']' {
|
||||
section := strings.TrimFunc(line[1:len(line)-1], unicode.IsSpace)
|
||||
section = strings.ToLower(section)
|
||||
dict[section] = make(map[string]string)
|
||||
return section, nil
|
||||
}
|
||||
|
||||
// key = value
|
||||
if m := regDoubleQuote.FindAllStringSubmatch(line, 1); m != nil {
|
||||
dict.add(section, m[0][1], m[0][2])
|
||||
return section, nil
|
||||
} else if m = regSingleQuote.FindAllStringSubmatch(line, 1); m != nil {
|
||||
dict.add(section, m[0][1], m[0][2])
|
||||
return section, nil
|
||||
} else if m = regNoQuote.FindAllStringSubmatch(line, 1); m != nil {
|
||||
dict.add(section, m[0][1], strings.TrimFunc(m[0][2], unicode.IsSpace))
|
||||
return section, nil
|
||||
} else if m = regNoValue.FindAllStringSubmatch(line, 1); m != nil {
|
||||
dict.add(section, m[0][1], "")
|
||||
return section, nil
|
||||
}
|
||||
|
||||
return section, newError("iniparser: syntax error at ")
|
||||
}
|
||||
|
||||
func (dict Dict) add(section, key, value string) {
|
||||
key = strings.ToLower(key)
|
||||
dict[section][key] = value
|
||||
}
|
||||
|
||||
func (dict Dict) GetBool(section, key string) (bool, bool) {
|
||||
sec, ok := dict[section]
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
value, ok := sec[key]
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
v := value[0]
|
||||
if v == 'y' || v == 'Y' || v == '1' || v == 't' || v == 'T' {
|
||||
return true, true
|
||||
}
|
||||
if v == 'n' || v == 'N' || v == '0' || v == 'f' || v == 'F' {
|
||||
return false, true
|
||||
}
|
||||
return false, false
|
||||
}
|
||||
|
||||
func (dict Dict) SetBool(section, key string, value bool) {
|
||||
dict.SetString(section, key, strconv.FormatBool(value))
|
||||
}
|
||||
|
||||
func (dict Dict) GetString(section, key string) (string, bool) {
|
||||
sec, ok := dict[section]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
value, ok := sec[key]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return value, true
|
||||
}
|
||||
|
||||
func (dict Dict) SetString(section, key, value string) {
|
||||
_, ok := dict[section]
|
||||
if !ok {
|
||||
dict[section] = make(map[string]string)
|
||||
}
|
||||
dict[section][key] = value
|
||||
}
|
||||
|
||||
func (dict Dict) GetInt(section, key string) (int, bool) {
|
||||
sec, ok := dict[section]
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
value, ok := sec[key]
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
i, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
return i, true
|
||||
}
|
||||
|
||||
func (dict Dict) SetInt(section, key string, value int) {
|
||||
dict.SetString(section, key, strconv.FormatInt(int64(value), 10))
|
||||
}
|
||||
|
||||
func (dict Dict) GetDouble(section, key string) (float64, bool) {
|
||||
sec, ok := dict[section]
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
value, ok := sec[key]
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
d, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
return d, true
|
||||
}
|
||||
|
||||
func (dict Dict) SetDouble(section, key string, value float64) {
|
||||
dict.SetString(section, key, strconv.FormatFloat(value, 'f', -1, 64))
|
||||
}
|
||||
|
||||
func (dict Dict) Delete(section, key string) {
|
||||
_, ok := dict[section]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
delete(dict[section], key)
|
||||
// If there are no items left in the section,
|
||||
// delete the section.
|
||||
if len(dict[section]) == 0 {
|
||||
delete(dict, section)
|
||||
}
|
||||
}
|
||||
|
||||
func (dict Dict) GetSections() []string {
|
||||
size := len(dict)
|
||||
sections := make([]string, size)
|
||||
i := 0
|
||||
for section, _ := range dict {
|
||||
sections[i] = section
|
||||
i++
|
||||
}
|
||||
return sections
|
||||
}
|
||||
|
||||
func (dict Dict) String() string {
|
||||
return (*dict.format()).String()
|
||||
}
|
||||
|
||||
func (dict Dict) format() *bytes.Buffer {
|
||||
var buffer bytes.Buffer
|
||||
for key, val := range dict[""] {
|
||||
buffer.WriteString(fmt.Sprintf("%s = %s\n", key, val))
|
||||
}
|
||||
buffer.WriteString("\n")
|
||||
for section, vals := range dict {
|
||||
if section == "" {
|
||||
continue
|
||||
}
|
||||
buffer.WriteString(fmt.Sprintf("[%s]\n", section))
|
||||
for key, val := range vals {
|
||||
buffer.WriteString(fmt.Sprintf("%s = %s\n", key, val))
|
||||
}
|
||||
buffer.WriteString("\n")
|
||||
}
|
||||
return &buffer
|
||||
}
|
||||
|
||||
func newError(message string) (e error) {
|
||||
return Error(message)
|
||||
}
|
||||
191
vendor/github.com/glacjay/goini/ini_test.go
generated
vendored
Normal file
191
vendor/github.com/glacjay/goini/ini_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
package ini
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
dict Dict
|
||||
err error
|
||||
)
|
||||
|
||||
func init() {
|
||||
dict, err = Load("example.ini")
|
||||
}
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Example: load error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileWithSpaces(t *testing.T) {
|
||||
if err := ioutil.WriteFile("testLoadFileWithSpaces.ini", []byte(" "), 0777); err != nil {
|
||||
t.Error("Unable to write test file")
|
||||
}
|
||||
defer os.Remove("testLoadFileWithSpaces.ini")
|
||||
|
||||
if _, err := Load("testLoadFileWithSpaces.ini"); err != nil {
|
||||
t.Error("Load: Couldn't load ini file with line consisting only of spaces.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrite(t *testing.T) {
|
||||
d, err := Load("empty.ini")
|
||||
if err != nil {
|
||||
t.Error("Example: load error:", err)
|
||||
}
|
||||
d.SetString("", "key", "value")
|
||||
tempFile, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
t.Error("Write: Couldn't create temp file.", err)
|
||||
}
|
||||
err = Write(tempFile.Name(), &d)
|
||||
if err != nil {
|
||||
t.Error("Write: Couldn't write to temp config file.", err)
|
||||
}
|
||||
contents, err := ioutil.ReadFile(tempFile.Name())
|
||||
if err != nil {
|
||||
t.Error("Write: Couldn't read from the temp config file.", err)
|
||||
}
|
||||
if string(contents) != "key = value\n\n" {
|
||||
t.Error("Write: Contents of the config file doesn't match the expected.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBool(t *testing.T) {
|
||||
b, found := dict.GetBool("pizza", "ham")
|
||||
if !found || !b {
|
||||
t.Error("Example: parse error for key ham of section pizza.")
|
||||
}
|
||||
b, found = dict.GetBool("pizza", "mushrooms")
|
||||
if !found || !b {
|
||||
t.Error("Example: parse error for key mushrooms of section pizza.")
|
||||
}
|
||||
b, found = dict.GetBool("pizza", "capres")
|
||||
if !found || b {
|
||||
t.Error("Example: parse error for key capres of section pizza.")
|
||||
}
|
||||
b, found = dict.GetBool("pizza", "cheese")
|
||||
if !found || b {
|
||||
t.Error("Example: parse error for key cheese of section pizza.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStringIntAndDouble(t *testing.T) {
|
||||
str, found := dict.GetString("wine", "grape")
|
||||
if !found || str != "Cabernet Sauvignon" {
|
||||
t.Error("Example: parse error for key grape of section wine.")
|
||||
}
|
||||
i, found := dict.GetInt("wine", "year")
|
||||
if !found || i != 1989 {
|
||||
t.Error("Example: parse error for key year of section wine.")
|
||||
}
|
||||
str, found = dict.GetString("wine", "country")
|
||||
if !found || str != "Spain" {
|
||||
t.Error("Example: parse error for key grape of section wine.")
|
||||
}
|
||||
d, found := dict.GetDouble("wine", "alcohol")
|
||||
if !found || d != 12.5 {
|
||||
t.Error("Example: parse error for key grape of section wine.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetBoolAndStringAndIntAndDouble(t *testing.T) {
|
||||
dict.SetBool("pizza", "ham", false)
|
||||
b, found := dict.GetBool("pizza", "ham")
|
||||
if !found || b {
|
||||
t.Error("Example: bool set error for key ham of section pizza.")
|
||||
}
|
||||
dict.SetString("pizza", "ham", "no")
|
||||
n, found := dict.GetString("pizza", "ham")
|
||||
if !found || n != "no" {
|
||||
t.Error("Example: string set error for key ham of section pizza.")
|
||||
}
|
||||
dict.SetInt("wine", "year", 1978)
|
||||
i, found := dict.GetInt("wine", "year")
|
||||
if !found || i != 1978 {
|
||||
t.Error("Example: int set error for key year of section wine.")
|
||||
}
|
||||
dict.SetDouble("wine", "not-exists", 5.6)
|
||||
d, found := dict.GetDouble("wine", "not-exists")
|
||||
if !found || d != 5.6 {
|
||||
t.Error("Example: float set error for not existing key for wine.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
d, err := Load("empty.ini")
|
||||
if err != nil {
|
||||
t.Error("Example: load error:", err)
|
||||
}
|
||||
d.SetString("pizza", "ham", "yes")
|
||||
d.Delete("pizza", "ham")
|
||||
_, found := d.GetString("pizza", "ham")
|
||||
if found {
|
||||
t.Error("Example: delete error for key ham of section pizza.")
|
||||
}
|
||||
if len(d.GetSections()) > 1 {
|
||||
t.Error("Only a single section should exist after deletion.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNotExist(t *testing.T) {
|
||||
_, found := dict.GetString("not", "exist")
|
||||
if found {
|
||||
t.Error("There is no key exist of section not.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSections(t *testing.T) {
|
||||
sections := dict.GetSections()
|
||||
if len(sections) != 3 {
|
||||
t.Error("The number of sections is wrong:", len(sections))
|
||||
}
|
||||
for _, section := range sections {
|
||||
if section != "" && section != "pizza" && section != "wine" {
|
||||
t.Errorf("Section '%s' should not be exist.", section)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
d, err := Load("empty.ini")
|
||||
if err != nil {
|
||||
t.Error("Example: load error:", err)
|
||||
}
|
||||
d.SetBool("", "key1", true)
|
||||
d.SetString("section1", "key1", "value2")
|
||||
d.SetInt("section1", "key2", 5)
|
||||
d.SetDouble("section1", "key3", 1.3)
|
||||
d.SetDouble("section2", "key1", 5.0)
|
||||
reader := strings.NewReader(d.String())
|
||||
d2, err := LoadReader(bufio.NewReader(reader))
|
||||
if err != nil {
|
||||
t.Error("Example: load error:", err)
|
||||
}
|
||||
b, found := d2.GetBool("", "key1")
|
||||
if !found || !b {
|
||||
t.Errorf("Stringify failed for key1")
|
||||
}
|
||||
s, found := d2.GetString("section1", "key1")
|
||||
if !found || s != "value2" {
|
||||
t.Error("Stringify failed for section1, key1")
|
||||
}
|
||||
i, found := d2.GetInt("section1", "key2")
|
||||
if !found || i != 5 {
|
||||
t.Error("Stringify failed for section1, key2")
|
||||
}
|
||||
db, found := d2.GetDouble("section1", "key3")
|
||||
if !found || db != 1.3 {
|
||||
t.Error("Stringify failed for section1, key3")
|
||||
}
|
||||
db, found = d2.GetDouble("section2", "key1")
|
||||
if !found || db != 5.0 {
|
||||
t.Error("Stringify failed for section2, key1")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue