config

package
v0.22.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Cross-platform configuration manager

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Base    string
	Entries map[string]ConfigEntry
}

func NewConfig

func NewConfig(base string) (config *Config)

Create a new Config manager

Example
package main

import (
	"fmt"
	"github.com/ddollar/config"
)

func main() {
	conf := config.NewConfig("myapp")
	fmt.Println(conf.Base)
}
Output:

myapp

func (*Config) Delete

func (c *Config) Delete(name, key string) (err error)

Delete a config key/value pair

Example
package main

import (
	"fmt"
	"github.com/ddollar/config"
)

func main() {
	conf := config.NewConfig("myapp")
	conf.Save("logins", "user@example.org", "12345")
	conf.Save("logins", "user2@example.org", "12345")
	conf.Delete("logins", "user2@example.org")
	logins, _ := conf.List("logins")
	fmt.Println(logins)
}
Output:

[user@example.org]

func (*Config) List

func (c *Config) List(name string) (keys []string, err error)

List keys for a given config

Example
package main

import (
	"fmt"
	"github.com/ddollar/config"
)

func main() {
	conf := config.NewConfig("myapp")
	conf.Save("logins", "user@example.org", "12345")
	conf.Save("logins", "user2@example.org", "12345")
	logins, _ := conf.List("logins")
	fmt.Println(logins)
}
Output:

[user2@example.org user@example.org]

func (*Config) Load

func (c *Config) Load(name, key string) (body string, err error)

Load a value for a config key

Example
package main

import (
	"fmt"
	"github.com/ddollar/config"
)

func main() {
	conf := config.NewConfig("myapp")
	conf.Save("logins", "user@example.org", "12345")
	password, _ := conf.Load("logins", "user@example.org")
	fmt.Println(password)
}
Output:

12345

func (*Config) Save

func (c *Config) Save(name, key, value string) (err error)

Save a key/value pair for a config

Example
package main

import (
	"fmt"
	"github.com/ddollar/config"
)

func main() {
	conf := config.NewConfig("myapp")
	conf.Save("logins", "user@example.org", "12345")
	password, _ := conf.Load("logins", "user@example.org")
	fmt.Println(password)
}
Output:

12345

type ConfigEntry

type ConfigEntry struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL