Add usage example to README
diff --git a/README.md b/README.md index 432b7e3..02872ba 100644 --- a/README.md +++ b/README.md
@@ -10,6 +10,34 @@ import "github.com/pelletier/go-toml" +## Usage + +Say you have a TOML file that looks like this: + +```toml +[postgres] +user = "pelletier" +password = "mypassword" +``` + +Read the username and password like this: + +```go +import ( + "fmt" + "github.com/pelletier/go-toml" +) + +config, err := toml.LoadFile("config.toml") +if err != nil { + fmt.Println("Error ", err.Error()) +} +configTree := config.Get("postgres").(*toml.TomlTree) +user := configTree.Get("user").(string) +password := configTree.Get("password").(string) +fmt.Println("User is ", user, ". Password is ", password) +``` + ## Documentation The documentation is available at