diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-06-21 19:06:17 -0700 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-06-21 19:06:17 -0700 |
commit | 42f28ab8e374137fe3f5d25424489d879d4724f8 (patch) | |
tree | 20353f2446b506d32e6d353b72a57bf48f070389 /vendor/github.com/pelletier/go-toml/README.md | |
parent | 6b39c308d882a0aeac533f8ab1d90b48a2ae4b5a (diff) | |
download | chat-42f28ab8e374137fe3f5d25424489d879d4724f8.tar.gz chat-42f28ab8e374137fe3f5d25424489d879d4724f8.tar.bz2 chat-42f28ab8e374137fe3f5d25424489d879d4724f8.zip |
Updating server dependancies (#6712)
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/README.md')
-rw-r--r-- | vendor/github.com/pelletier/go-toml/README.md | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/vendor/github.com/pelletier/go-toml/README.md b/vendor/github.com/pelletier/go-toml/README.md index 8279102b1..22da41a81 100644 --- a/vendor/github.com/pelletier/go-toml/README.md +++ b/vendor/github.com/pelletier/go-toml/README.md @@ -17,64 +17,62 @@ Go-toml provides the following features for using data parsed from TOML document * Load TOML documents from files and string data * Easily navigate TOML structure using Tree +* Mashaling and unmarshaling to and from data structures * Line & column position data for all parsed elements * [Query support similar to JSON-Path](query/) * Syntax errors contain line and column numbers -Go-toml is designed to help cover use-cases not covered by reflection-based TOML parsing: +## Import -* Semantic evaluation of parsed TOML -* Informing a user of mistakes in the source document, after it has been parsed -* Programatic handling of default values on a case-by-case basis -* Using a TOML document as a flexible data-store +```go +import "github.com/pelletier/go-toml" +``` -## Import +## Usage example - import "github.com/pelletier/go-toml" +Read a TOML document: -## Usage +```go +config, _ := toml.LoadString(` +[postgres] +user = "pelletier" +password = "mypassword"`) +// retrieve data directly +user := config.Get("postgres.user").(string) -### Example +// or using an intermediate object +postgresConfig := config.Get("postgres").(*toml.Tree) +password = postgresConfig.Get("password").(string) +``` + +Or use Unmarshal: -Say you have a TOML file that looks like this: +```go +type Postgres struct { + User string + Password string +} +type Config struct { + Postgres Postgres +} -```toml +doc := []byte(` [postgres] user = "pelletier" -password = "mypassword" +password = "mypassword"`) + +config := Config{} +Unmarshal(doc, &config) +fmt.Println("user=", config.Postgres.User) ``` -Read the username and password like this: +Or use a query: ```go -import ( - "fmt" - "github.com/pelletier/go-toml" -) - -config, err := toml.LoadFile("config.toml") -if err != nil { - fmt.Println("Error ", err.Error()) -} else { - // retrieve data directly - user := config.Get("postgres.user").(string) - password := config.Get("postgres.password").(string) - - // or using an intermediate object - configTree := config.Get("postgres").(*toml.Tree) - user = configTree.Get("user").(string) - password = configTree.Get("password").(string) - fmt.Println("User is ", user, ". Password is ", password) - - // show where elements are in the file - fmt.Println("User position: %v", configTree.GetPosition("user")) - fmt.Println("Password position: %v", configTree.GetPosition("password")) - - // use a query to gather elements without walking the tree - results, _ := config.Query("$..[user,password]") - for ii, item := range results.Values() { - fmt.Println("Query result %d: %v", ii, item) - } +// use a query to gather elements without walking the tree +results, _ := config.Query("$..[user,password]") +for ii, item := range results.Values() { + fmt.Println("Query result %d: %v", ii, item) } ``` |